We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
An easy intervals problem, graded against 6 test cases (3 of them hidden).
Sorting by start or end, then merging or scheduling overlapping ranges.
Reach for it when you see: Meetings, bookings, ranges, or anything with a start and an end.
More Intervalsproblems →The brute force compares all pairs, O(n^2). Sorting by start time buys a much stronger property: if any two meetings overlap at all, then some adjacent pair in sorted order overlaps. So a single pass over neighbours settles it.
For each consecutive pair, the conflict test is `next.start < current.end`. Getting the boundary right is the whole problem: with `<=` you would reject `[1,2]` and `[2,3]`, which are back-to-back rather than overlapping. Interviewers reliably probe this case, and it is worth stating your convention out loud before you write the comparison.
Sorting dominates the runtime; the scan is linear.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.