15% off all plans & roadmaps Use code
See plansProblem editorial
Given nums, an array of integers, arrange all of its elements in ascending order. Ascending order means each element is less than or equal to the element that follows it, so duplicate values remain present with the same frequency.
Sort an Array is a Greedy Patterns problem, in the Sorting Based subpattern. The pattern covers interval scheduling, jump games, stock trading, and task scheduling
The reference solution runs in O(n log n) time and O(n) auxiliary space, plus O(log n) recursion stack space.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Sort an Array is a Greedy Patterns problem, in the Sorting Based subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.