Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

Closed integer intervals are [(1, 2), (3, 4), (2, 5), (6, 7), (8, 9)]. How many unordered pairs of these intervals are disjoint (share no integer point)?

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

Correct answer: A. 8

Closed intervals are disjoint when one ends strictly before the other starts; of the 10 pairs only (1,2)-(2,5) and (3,4)-(2,5) overlap, so 8. Treating a shared endpoint as disjoint gives 9, 2 counts the overlapping pairs and 5 the intervals.

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

Exams that ask this topic