TL;DR
- Sorting questions test comparator design as much as algorithm knowledge.
- For frontend work, custom ordering and stable presentation logic matter more than implementing quicksort from memory.
- I focus on ranking, grouping, interval sorting, and multi-key comparisons.
Context
Sorting shows up in feeds, tables, dashboards, search ranking, release timelines, and admin tools. The real skill is defining a precise order rule that stays consistent across edge cases.
The Approach
Practice these 10 medium-level questions:
- Sort Objects by Multiple Keys — e.g. severity desc, then createdAt asc.
- Stable Sort by Status Priority — preserve original order inside a bucket.
- Sort Version Strings — semantic-ish comparison without string mistakes.
- Merge K Sorted Lists — classic partial-order aggregation.
- Sort Colors / Dutch National Flag — three-way partitioning.
- Top K Largest Elements — heap or partial sort reasoning.
- Reorder Log Files — letter logs before digit logs with stable digit order.
- Sort Intervals by Length Then Start — composite comparator discipline.
- Sort Matrix Diagonals — partition data into groups, sort, then rebuild.
- Arrange Largest Number — comparator based on concatenation, not numeric value.
Try it in the browser
Browser Practice
Sorting practice: multi-key comparator
Implement solve(records) and sort by score descending, then name ascending.
Sample Tests
1 checks
Function name:
solveBest for JavaScript / TypeScript / JSON practice snippets.Monospace editorRuns in browser sandbox
Trade-offs
- Native sorting APIs are convenient, but comparator bugs can create inconsistent results that are hard to catch.
- Full sorting is often unnecessary if the real need is top-k selection or grouped ordering.
References
- Related: Coding Practice: Searching
- Related: Coding Practice: Arrays