Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA

Balloons span closed integer intervals [1,4], [2,3], [4,6], [5,8], [7,9]. One arrow shot at integer x bursts every balloon whose interval contains x. What is the minimum number of arrows?

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

Correct answer: D. 3

Sort by right endpoint and shoot at the smallest end; every balloon starting at or before that point is burst by the same arrow. Shooting at the left endpoint of each balloon wastes arrows.

More Coding Interview Problems questions

Exams that ask this topic