Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Move Zeros to Array End

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Move Zeros to Array End. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an integer array nums, move all 0 values to the end of the array while preserving the relative order of the non-zero elements. Modify the array in place and return the resulting array.

Constraints

  • 1 <= nums.length <= 10^5
  • -2^31 <= nums[i] <= 2^31 - 1
  • The relative order of non-zero elements must be preserved
  • Modify the array in place

Function Signature

def move_zeroes(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output