Applied AI Engineer (LLM) coding learning path Level 2 This level · 22 of 31

Merge Intervals

Medium Intervals Sorting

Problem

Given a list of intervals, merge every overlapping pair and return the resulting disjoint intervals in order.

Original: LeetCode 56: Merge Intervals.

Examples

Example 1

Input`intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]`
Output`[[1, 6], [8, 10], [15, 18]]`

Example 2

Input`intervals = [[1, 4], [4, 5]]`
Output`[[1, 5]]`

Touching intervals count as overlapping.

Constraints

  • 1 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= starti <= endi <= 10^4

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (1)
  1. LeetCode 56: Merge Intervalsleetcode.com
Previous
Next