Merge Intervals
Merge all overlapping intervals Intervals [1,4] and [4,5] are considered overlapping Example: [[1,3],[2,6],[8,10],[15,18]] => [[1,6],[8,10],[15,18]]
This one is all about overlap reasoning and clean boundary handling. Interviewers love it because it reveals your overlap reasoning and your edge-case discipline. Be precise about inclusive/exclusive boundaries; that's what interviewers poke at.
Examples
You write
merge(intervals: List[List[int]])
Example 1
- Input
- [[1,3],[2,6],[8,10],[15,18]]
- returns
- [[1,6],[8,10],[15,18]]
Example 2
- Input
- [[1,4],[4,5]]
- returns
- [[1,5]]
The pattern behind it
Arrays & Hashing
I reach for it when
- You catch yourself scanning the array again for every element.
- The problem asks about duplicates, pairs, counts or groups.
Say this before you type. Say what the key is and what the value remembers, before you write the loop.
All 127 Arrays & Hashing problemsIntervals
I reach for it when
- The input is ranges: meetings, bookings or segments.
- The question asks about overlaps, merges or gaps.
Say this before you type. Say what you sort by, and whether two ranges that touch count as overlapping.
All 6 Intervals problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.
Prep guides that list this problem
Our company tags come from public interview write-ups. None of these is a confirmed question.