Skip to content

Minimum Number of Arrows to Burst Balloons

MediumIntervals
Decode it first. Clues, constraints, pattern and plan before any code.

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.

[[10, 16], [2, 8], [1, 6], [7, 12]]  →  2   (shoot at 6 and at 11)
[[1, 2], [3, 4], [5, 6], [7, 8]]     →  4
[[1, 2], [2, 3], [3, 4], [4, 5]]     →  2   (shoot at 2 and at 4)

Constraints

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