- Move Zeroes (LeetCode 283): Interview Notes
- Problem
- Given an integer array nums, move all 0's to the end while keeping the relative order of the non-zero elements. Do this in-place.
- Approach
- Two pointers: write index w starts at 0. Scan read index r; whenever nums[r] != 0, write it to nums[w] and increment w. After the scan, fill nums[w:] with zeros. Narrate a dry run on [0,1,0,3,12].
- Complexity
- Time O(n), space O(1).
- Practice tip: https://www.linkjob.ai/
- Disclosure: I work on Linkjob AI.
