Skip to content

Foundations -> Sorting

Sorting as a modeling tool: order data to expose monotonicity, simplify sweeps, or make greedy decisions provable.

  • Topic slug: foundations/sorting
  • Tutorial page: Open tutorial
  • Ladder page: Open ladder
  • Repo problems currently tagged here: 5
  • Repo companion pages: 0
  • Curated external problems: 7

Microtopics

  • custom-comparator
  • stable-sort
  • pair-sorting
  • event-sorting
  • coordinate-compression

Learning Sources

Source Type
OI Wiki sorting intro Reference
cppreference std::sort Primary
Competitive Programmer's Handbook Reference

Practice Sources

Source Type
CSES Problem Set Practice
Codeforces sortings tag Practice

Curated External Problems

Core

Problem Source Difficulty Context Style Prerequisites Tags Why it fits
Apartments CSES Easy - Greedy-Heavy; Implementation-Heavy Sorting; Two Pointers; Greedy Matching Two-Pointers; Matching; Sort A classic sorted two-pointer matching problem with a very clean greedy proof.
Movie Festival CSES Easy - Greedy-Heavy Sorting; Interval Scheduling; Greedy Intervals; Sort A textbook interval-scheduling problem that rewards sorting by finish time.
Reading Books CSES Easy - Greedy-Heavy Sorting; Greedy Scheduling; Prefix Sums Scheduling A nice example of sorting plus a simple optimization argument.
Tasks and Deadlines CSES Medium - - - Sort; Ordering A very standard sort-by-duration optimization.

Classics

Problem Source Difficulty Context Style Prerequisites Tags Why it fits
Ferris Wheel CSES Easy - Greedy-Heavy Sorting; Pairing; Two Pointers Two-Pointers; Pairing; Sort One of the most recognizable introductory sorting-and-greedy pairings.
Stick Lengths CSES Medium - Math-Heavy; Greedy-Heavy Sorting; Median; Absolute Deviations Median; Absolute-Deviation A classic benchmark for the median-minimizes-L1-cost idea after sorting.

Advanced

Problem Source Difficulty Context Style Prerequisites Tags Why it fits
Nested Ranges Check CSES Medium - Proof-Heavy; Greedy-Heavy Sorting; Interval Containment; Sweep-Line Ideas Intervals; Containment A strong sorting problem where handling interval order and ties is the main challenge.

Repo Problems

Code Title Fit Difficulty Pattern Note Solution
APARTMENTS Apartments secondary easy-medium two sorted pointers; tolerance matching; greedy monotone scan Note Code
FERRISWHEEL Ferris Wheel primary easy-medium opposite end pointers; greedy pairing; sorted capacity matching Note Code
LEMONADELINE Lemonade Line secondary easy descending tolerance order; prefix feasibility count; minimize accepted arrivals Note Code
MOVIEFESTIVAL Movie Festival primary easy finish-time sorting; interval scheduling; exchange argument greedy Note Code
SUMOFTWOVALUES Sum of Two Values secondary medium sort and scan; opposite end pointers; index restoration Note Code

Regeneration

python3 scripts/generate_problem_catalog.py