FAANG · LeetCode #56
Merge Intervals — three-stage drill
1The ProblemMedium
Merge Intervals
Merge all overlapping intervals and return the non-overlapping set.
Examples
[[1,3],[2,6],[8,14],[9,11],[15,18]]→ [[1,6],[8,14],[15,18]][[1,4],[4,5]]→ [[1,5]]
constraintSort by start first; then a single left-to-right sweep merges in place.
2The PatternTIME O(n log n) · SPACE O(n)
Intervals
Given a pile of ranges, sort them by start — now any overlap is a neighbour, so a single left→right pass handles them.
Problems using this pattern
3The SolutionRESULT → [[1,6],[8,14],[15,18]]
Step through it
the input as given — not yet sorted
Step 1 / 12
Arrow keys to navigate · escape to reset