LeetCode 57 ·
Medium
Insert Interval
Insert a new interval into a sorted list of non-overlapping intervals, merging as needed.
Try it
Step through the core mechanic. The simulator below runs the greedy shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Greedy — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
Copy intervals ending before the new one, merge all that overlap by extending the new interval's bounds, then copy the rest. One linear pass since the input is already sorted.
| Aspect | Value |
|---|---|
| Pattern | Greedy |
| Recognise it by | Splice one interval into a sorted, non-overlapping list. |
| Time complexity | O(n) |
| Space complexity | O(n) |
| Difficulty | Medium |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.