Intervals mind map
Merge, insert, and schedule interval problems.
Core idea: Normalize endpoints and sort; every relationship becomes gap, touch, or overlap.
Mnemonic: Sort → compare endpoints → fold · Cost: O(n log n) sort · O(n) sweep
Fold: Merge & insert
Signal: Overlapping ranges should collapse into their union.
Move: Carry one active interval; extend it on overlap or emit it when a real gap begins.
Examples: Merge Intervals, Insert Interval, Summary Ranges
Choose: Maximum compatibility
Signal: The goal is to keep the most non-overlapping work.
Move: Sort by earliest finish and accept the next interval that starts after the chosen end.
Examples: Erase Overlap, Meeting Selection, Minimum Arrows
Sweep: Endpoint events
Signal: You need maximum concurrency or state at every boundary.
Move: Encode start and end deltas, sort events with correct tie rules, then scan active count.
Examples: Meeting Rooms II, Skyline, Maximum Population
Index: Ordered boundaries
Signal: Ranges arrive online and must be queried, booked, or removed.
Move: Maintain searchable endpoints; state open/closed boundary semantics before updating.
Examples: My Calendar, Range Module, Employee Free Time