Loading practice problems…
Loading your practice workspace…
Loading code editor…
19 / 29
Sign in
Algorithms/Merge Sort

Sort an Array

medium35 min

Given an array of integers, return the values in ascending order.

Implement merge sort instead of using a built-in sorting function.

Example 1

Inputnums = [5, 2, 3, 1]

Output[1, 2, 3, 5]

Example 2

Inputnums = [5, 1, 1, 2, 0, 0]

Output[0, 0, 1, 1, 2, 5]

Constraints

  • 1 ≤ nums.length ≤ 50,000
  • -50,000 ≤ nums[i] ≤ 50,000
Merge SortDivide and Conquer