FastPrepMove Zeroes

Move Zeroes

Bloomberg LP logoBloomberg LP● EasyNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated

Problem statement

Given an integer array nums, move all zeroes to the end in place and return the array.

Keep the nonzero values in their original relative order.

Function

moveZeroes(nums: int[]) → int[]

Examples

Example 1

nums = [0,1,0,3,12]return = [1,3,12,0,0]

The nonzero values keep their order, and both zeroes move to the end.

Example 2

nums = [0]return = [0]

The only element is already zero, so the array stays unchanged.

Constraints

  • 0 <= nums.length <= 10^5.
  • Each value is a signed 32-bit integer.

More Bloomberg LP Phone Screen questions

Similar questions at other companies

Interview reports that mention this question

Bloomberg LP interview experiences

All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int[] moveZeroes(int[] nums) {
        // Write your code here.
    }

}
Checking account…