Sort an Array

Given an array of integers nums, sort the array in ascending order and return it.

You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallest space complexity possible.

Example 1
Inputnums = [5,2,3,1]
Output[1,2,3,5]
After sorting the array, the positions of some numbers are not changed, such as 2 and 3, while the positions of other numbers are changed, such as 1 and 5.
Example 2
Inputnums = [5,1,1,2,0,0]
Output[0,0,1,1,2,5]
The values of nums are not necessarily unique.

Constraints

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

Asked at 12 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate