Problems that get easy once sorted: counting sort, the middle element, neighbour gaps, intervals and buckets.
Key ideas
- Sorting puts "close" things side by side: nearest pairs, overlaps, the median.
sorted(xs, key=...)and tuple keys: the first criterion, then the second on ties.- With a small range of values, counting (counting sort) beats sorting.
Pattern
order = sorted(items, key=lambda it: (it[0], -it[1]))
for prev, cur in zip(order, order[1:]):
...Finish these first:Two Pointers & Sliding WindowRecursion & Divide and Conquer
Lessons
Each lesson explains one idea from zero and ends with a few tasks. Lessons open in order; the explanation can be read at any time.
Boss
06
Maximum Gap
Function
The boss opens when every lesson of the topic is finished. Solve it too and the topic is complete, and the topics after it open.