Skip to content
Decoder

Divide Intervals Into Minimum Number of Groups

Medium

Problem

intervals[i] = [left, right] is an inclusive interval. Divide all of them into groups so that no two intervals in the same group intersect. Two intervals intersect if they share at least one number, so [1, 5] and [5, 8] intersect. Return the minimum number of groups.

Example 1

Input
[[5, 10], [6, 8], [1, 5], [2, 3], [1, 10]]
Output
3

Example 2

Input
[[1, 3], [5, 6], [8, 10], [11, 13]]
Output
1

Constraints

  • 1 <= intervals.length <= 10^5
  • 1 <= left <= right <= 10^6

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.