Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Move Feed Zeroes In-Place

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

Your question is Move Feed Zeroes In-Place. 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

In a Meta mobile client, you may need to compact an integer buffer before rendering a Facebook feed module. Given an integer array nums, move all 0 values to the end of the array in place while keeping the relative order of all non-zero values unchanged.

Return the modified array.

Formal Specification

  • Input: nums, a list of integers
  • Output: The same list after all zeroes have been moved to the end
  • Requirement: Do not create another array for the final result; modify the input array in place

Constraints

  • 1 <= len(nums) <= 10^5
  • -2^31 <= nums[i] <= 2^31 - 1
  • The relative order of non-zero elements must be preserved
  • The array must be modified in place
  • Aim for O(n) time and O(1) extra space

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