Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: Balloons are shot with arrows that burst every balloon whose horizontal interval contains the arrow's x position. Intervals are [10,16], [2,8], [1,6], [7,12]. What is the minimum number of arrows needed to burst all balloons?

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

Sort by right endpoint and shoot as far right as possible, reusing an arrow while intervals still overlap. Sorting by left endpoint and shooting at each left end overcounts.

More Coding Interview Problems questions

Exams that ask this topic