FastPrepSort an Array Fast

Sort an Array Fast

Adobe logoAdobe● MediumINTERNPHONE SCREEN

Updated

Problem statement

Given an array of integers nums, return a new array with the same numbers in increasing order. Equal numbers all stay in the result.

Write the sort yourself with a method that takes O(n log n) time on average, such as quicksort or merge sort. The judge checks only the returned array, so this rule is for your practice and is not checked.

Function

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

Examples

Example 1

nums = [5,-2,9,0,-2]return = [-2,-2,0,5,9]

In increasing order: -2, -2, 0, 5, 9. Both copies of -2 stay in the result.

Example 2

nums = [42]return = [42]

One number is already sorted.

Example 3

nums = [10,9,100,1]return = [1,9,10,100]

Numbers are compared by value: 1 < 9 < 10 < 100. Comparing them as text would wrongly put 10 and 100 before 9.

Constraints

  • 1 <= nums.length <= 2000
  • -10^5 <= nums[i] <= 10^5

More Adobe Phone Screen questions

Similar questions at other companies

Interview reports that mention this question

Adobe interview experiences

All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int[] sortNumbers(int[] nums) {
        // Write your code here.
    }
}
Checking account…