Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Shift Zeros to the Right
00:00
5 left

Shift Zeros to the Right

MediumPython

Problem

Write a program to shift all zeroes to the right in an array.

Implement the operation in place and preserve the relative order of all nonzero elements. Return the modified array. The input is a list of integers with length from 1 through 1000.

Constraints

  • 1 <= nums.length <= 1000
  • -10^9 <= nums[i] <= 10^9
  • The transformation must be performed in place
  • The relative order of nonzero values must remain unchanged

Function Signature

def move_zeroes(nums):
Interviewer

Your question is Shift Zeros to the Right. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.