Link:
Track: Amazon tag

Question

Restate the problem

Edge Case


Method 1 - (Optimal) Two pointer
Method 2 - Brute force

Method 1

Approach

Complexity

  • Time Complexity: O(n)
  • Space Complexity: O(1)

Code

class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        left = 0
 
        for right, num in enumerate(nums):
            if nums[right] != 0:
                # swap
                nums[left], nums[right] = nums[right], nums[left]
 
                left += 1

History

  • Feb-22-2026 Hinted
  • Jan-07-2026 Peeked: no idea