Practice

Sort an Array

Module 14 · Sorting

Problem

Given an integer array nums, sort it in ascending order without calling a built-in sort function.

Examples

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 ≤ n ≤ 5·10⁴ · values in ±5·10⁴.

Attempt it first

The point of this problem isn't cleverness — it's writing a real O(n log n) sort correctly, from the ground up, using the concept lessons directly. Pick merge sort or quicksort and implement it fully before checking anything.