Dashboard
LC #57

Insert Interval

Pattern · ?AmazonGoogleMetaLinkedIn

Problem

Insert a new interval into a sorted non-overlapping list and merge if necessary.

Constraints

  • 0 ≤ n ≤ 10⁴
  • intervals is sorted by startᵢ and non-overlapping
  • 0 ≤ startᵢ ≤ endᵢ ≤ 10⁵

Example

Input
intervals = [[1,3],[6,9]], newInterval = [2,5]
Output
[[1,5],[6,9]]
Why
[1,3] and [2,5] overlap → merged to [1,5]; [6,9] untouched

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗