Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Intervals [1,4], [3,7] and [6,10] are available. What is the minimum number of these intervals needed to cover the whole segment [1, 10] (every point from 1 to 10 must be inside a chosen interval)?

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

Correct answer: A. 3

Point 5 lies only in [3,7], and point 6 lies in [3,7] and [6,10], so all three intervals are needed; dropping any one leaves a gap.

More Coding Interview Problems questions

Exams that ask this topic