← Problems

Merge Sort

MEDIUM
Problem⌘ K
SortingDivide & conquer

Merge Sort

Sort an array of integers in ascending order using a divide-and-conquer strategy. Aim for predictable O(n log n) time.

Example

Input nums = [5, 2, 3, 1]
Output [1, 2, 3, 5]

Constraints

1 ≤ nums.length ≤ 50,000.-50,000 ≤ nums[i] ≤ 50,000.

Think about

Try a first approach in the editor. Copilot reviews your actual code and asks one focused question when it finds a gap.

solution.c
Test resultsReady
$ Type your approach, then run the sample tests.
LIVE AI REVIEW · WAITING
Start typing or paste your attempt here.