DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Move Zeroes

**Problem Statement:** Given an integer array `nums`, move all `0`s to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. **Hint / Expected Approach:** Two-pointer in-place swap **Edge Cases to Consider:** - (1) All zeros - (2) No zeros - (3) Zeros only at the end

Examples

Example 1
Input: [0, 1, 0, 3, 12]
Output: [1, 3, 12, 0, 0]
Example 2
Input: [0]
Output: [0]
Example 3
Input: [0, 0, 0]
Output: [0, 0, 0]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪All zeros
  • ▪No zeros
  • ▪Zeros only at the end
Frequently Asked At
MicrosoftMetaAdobeFlipkartWipro