Data Structures & AlgorithmsHardTCS NQT · GATE CS

Closed integer intervals are [(1, 4), (2, 6), (5, 9), (3, 3), (6, 8), (7, 12)]. What is the largest number of intervals that share a common integer point?

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

Correct answer: A. 3

Sweep over points: add +1 at a start and −1 just after an end (end + 1, since ends are inclusive), then take the peak count. Treating the end as exclusive undercounts intervals that end exactly where another starts.

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

Exams that ask this topic