Move zeros to the front
Company: Uber
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates array manipulation and in-place algorithm competencies, including handling space-time trade-offs and preserving relative order (stability) while operating with O(1) extra space.
Examples
Input: ([4, 0, 5, 0, 3],)
Expected Output: [0, 0, 4, 5, 3]
Explanation: Prompt example.
Input: ([0, 0, 1],)
Expected Output: [0, 0, 1]
Explanation: Zeros already at front.
Input: ([1, 2, 3],)
Expected Output: [1, 2, 3]
Explanation: No zeros.
Input: ([],)
Expected Output: []
Explanation: Empty array.
Hints
- Fill non-zero values from right to left, then fill the prefix with zeros.