Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many disjoint intervals remain after merging all overlapping closed intervals in [(1,3),(2,6),(8,10),(15,18),(17,20),(6,7)]? (Intervals that share one endpoint count as overlapping.)

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

Correct answer: B. 3

Sort by start, then extend the last merged interval while the next start is at most its end. Closed intervals touching at an endpoint merge, so [1,6] and [6,7] join.

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

Exams that ask this topic