Skip to content
Decoder

Non-overlapping Intervals

Medium

Problem

Return the **minimum number of intervals to remove** so that the rest do not overlap. Intervals that only touch, like [1, 2] and [2, 3], do not overlap.

Example 1

Input
[[1, 2], [2, 3], [3, 4], [1, 3]]
Output
1
Why
remove [1, 3]

Example 2

Input
[[1, 2], [1, 2], [1, 2]]
Output
2

Example 3

Input
[[1, 2], [2, 3]]
Output
0

Constraints

  • 0 <= intervals.length <= 10^5
  • -5 * 10^4 <= start < end <= 5 * 10^4

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.