Approach Summary
Slow pointer tracks the position to place the next non-zero element. Fast pointer scans the array.
How to Recognize This Pattern
- Partition array in-place
- Preserve order
Complexity Analysis
Time Complexity
O(n)
Space Complexity
O(1)
Tags
Array Two Pointers