Data Structures & AlgorithmsModerateCodeforces Div2 C · TCS NQT

Balloons span the closed intervals [(1, 6), (2, 8), (7, 12), (10, 16), (3, 5), (14, 15), (8, 9)] on a horizontal line. An arrow shot at position x bursts every balloon whose interval contains x. What is the minimum number of arrows needed to burst all balloons?

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

Correct answer: C. 3

Sort by right endpoint, shoot at the earliest right end, and skip every balloon that it already bursts. Shooting at the midpoint of each balloon or shooting at the left end of the first balloon fails in general.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic