FastPrepSort an Absolute-Value-Sorted Array

Sort an Absolute-Value-Sorted Array

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

nums is sorted by nondecreasing absolute value. Return its values in ordinary nondecreasing numeric order in linear time.

Function

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

Examples

Example 1

nums = [0,-1,2,-4,5,6,-10,-13,-22]return = [-22,-13,-10,-4,-1,0,2,5,6]

Negative values reverse their absolute-value order before merging with nonnegative values.

Constraints

  • 0 <= nums.length <= 10^5.
  • Absolute values are nondecreasing.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] sortAbsoluteArray(int[] nums) {
  // Write your code here.
}
nums[0,-1,2,-4,5,6,-10,-13,-22]
expected[-22,-13,-10,-4,-1,0,2,5,6]
Checking account…