Module 13 · Greedy · Minimum Number of Arrows to Burst Balloons

Arrows to burst balloons

Sort the balloons by where they end. The balloon that ends first needs an arrow somewhere inside it, and the best place is its very end: as far right as possible, so the same arrow also bursts every later balloon that has started by then. The first balloon that starts after the arrow needs a new one, again at its own end.

Each bar is a balloon on the x-axis, numbered by its index as on the slides, one lane per balloon in sorted order. A vertical line is an arrow; green balloons are burst by the latest arrow, grey ones by an earlier one.