Skip to content
Decoder

Minimum Number of Arrows to Burst Balloons

Medium

Problem

Balloons are taped to a wall. Balloon i spans the horizontal range points[i] = [x_start, x_end]. An arrow shot straight up at position x bursts every balloon with x_start <= x <= x_end, and keeps flying. Return the minimum number of arrows needed to burst all the balloons.

Example 1

Input
[[10, 16], [2, 8], [1, 6], [7, 12]]
Output
2
Why
shoot at 6 and at 11

Example 2

Input
[[1, 2], [3, 4], [5, 6], [7, 8]]
Output
4

Example 3

Input
[[1, 2], [2, 3], [3, 4], [4, 5]]
Output
2
Why
shoot at 2 and at 4

Constraints

  • 1 <= points.length <= 10^5
  • -2^31 <= x_start < x_end <= 2^31 - 1

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.