Given an integer array nums, move all 0s to the end while maintaining the relative order of non-zero elements. Do it in-place.
Slow pointer tracks the position for the next non-zero element. Fast pointer scans all elements. When fast pointer finds a non-zero, swap with slow pointer and advance both.
- slow=0 (insertion point for non-zeros).
- For fast from 0 to n-1: if nums[fast]!=0, swap nums[slow] and nums[fast], slow++.
- Time Complexity: O(N)
- Space Complexity: O(1)