FastPrepMove Zeroes with Sorted Nonzero Values

Move Zeroes with Sorted Nonzero Values

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

Return an array containing all nonzero values from nums in ascending order, followed by the same number of zeroes as the input.

Function

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

Examples

Example 1

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

The nonzero values sort to 1,2,3 and two zeroes follow.

Example 2

nums = [0,0]return = [0,0]

There are no nonzero values.

Constraints

  • 0 <= nums.length <= 10^5.
  • Values are 32-bit signed integers.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] moveZeroesSorted(int[] nums) {
  // Write your code here.
}
nums[0,3,0,1,2]
expected[1,2,3,0,0]
Checking account…