Problem
FAANG · LeetCode #452

Minimum Number of Arrows to Burst Balloons — three-stage drill

1The ProblemMedium

Minimum Number of Arrows to Burst Balloons

Min arrows to pop every balloon, where one arrow fired at x bursts every balloon spanning that x.

burst every balloon — one arrow flies up at x and pops every balloon spanning that xballoonsA [10,16]B [2,8]C [1,6]D [7,12]024681012141618↑ x=6↑ x=12return2
Examples
[[10,16],[2,8],[1,6],[7,12]]→ 2[[1,10],[2,3],[5,6],[7,8]]→ 3

constraintBalloons are closed intervals [start, end]; an arrow at x bursts every balloon with start ≤ x ≤ end.

2The PatternTIME O(n log n) · SPACE O(n)

Intervals

Given a pile of ranges, sort them by start — now any overlap is a neighbour, so a single left→right pass handles them.

sort the ranges by start, then sweep once01234567891011[7,9][2,5][1,3][8,10]given: a pile of ranges in any order
Problems using this pattern
3The SolutionRESULT → 2

Step through it

given — balloons in arbitrary orderballoonsA [10,16]B [2,8]C [1,6]D [7,12]024681012141618
given: 4 balloons spanning x-ranges · burst all with the fewest arrows
Step 1 / 7
Arrow keys to navigate · escape to reset

All problems by pattern

Backtracking

Recursive Descent