Dashboard
LC #56

Merge Intervals

Pattern · ?AmazonGoogleMetaBloombergMicrosoft

Problem

Given an array of intervals, merge all overlapping intervals.

Constraints

  • 1 ≤ n ≤ 10⁴
  • intervals[i].length == 2
  • 0 ≤ startᵢ ≤ endᵢ ≤ 10⁴

Example

Input
intervals = [[1,3],[2,6],[8,10],[15,18]]
Output
[[1,6],[8,10],[15,18]]
Why
[1,3] and [2,6] overlap → merged to [1,6]

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗