~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Intervals / sweep line
Sort by start, merge; sweep events for overlaps.
Notes
Recognise it when: merging ranges, overlaps, meeting rooms, coverage, sweep line.
out = []
for s, e in sorted(intervals):
if out and s <= out[-1][1]: # <= merges touching intervals
out[-1][1] = max(out[-1][1], e)
else:
out.append([s, e])
- Insert into a sorted list: three phases (before, overlapping, after), O(n).
- Max concurrent (meeting rooms): sweep events
(s, +1)and(e, -1), sorted so an end comes before a start at the same time.
Gotchas: decide whether [1, 3] and [3, 5] overlap before writing any code.
14 problems
Interview roadmap
Intervals Merge, insert and sweep over ranges.
- Basics: do any meetings overlap? basics py · c++ · java easy
- Longest stretch with the shop open py · c++ · java easy
- Merge Intervals Roblox py · c++ · java easy
- Insert Interval py · c++ · java medium
- Meeting Rooms II py · c++ · java medium
- Worker hours, promotions and double pay 4 levels Anthropic py · c++ · java medium
- Shard rebalance with an overlap limit 3 levels OpenAI medium
- Split stays Airbnb py · c++ · java medium
- The first gap everyone shares Citadel py · c++ · java easy
- Punch one point out of a run of ranges Databricks easy
- Find restaurant intervals Pinterest py · c++ · java medium
- Design a meeting scheduler 2 levels AmazonUber py · c++ · java medium
- Minimum Interval to Include Each Query py · c++ · java hard
- Car Pooling py · c++ · java medium