Field note / fundamentals

publishedupdated 2026-05-04#algorithms#sorting#comparator#merge-sort#frontend

Coding Practice: Sorting

Ten medium-level sorting questions covering custom comparators, stable ordering, partial ordering, interval sorting, and ranked UI data.

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:

  1. Sort Objects by Multiple Keys — e.g. severity desc, then createdAt asc.
  2. Stable Sort by Status Priority — preserve original order inside a bucket.
  3. Sort Version Strings — semantic-ish comparison without string mistakes.
  4. Merge K Sorted Lists — classic partial-order aggregation.
  5. Sort Colors / Dutch National Flag — three-way partitioning.
  6. Top K Largest Elements — heap or partial sort reasoning.
  7. Reorder Log Files — letter logs before digit logs with stable digit order.
  8. Sort Intervals by Length Then Start — composite comparator discipline.
  9. Sort Matrix Diagonals — partition data into groups, sort, then rebuild.
  10. 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: solve
Best 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