Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

Intervals [(1, 6), (2, 4), (3, 9), (5, 7), (8, 10), (4, 5)] are given as closed ranges. You must remove the fewest intervals so that no remaining interval fully contains another. What is the minimum number of removals?

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

Correct answer: A. 2

Sort by start ascending and end descending, then the kept intervals must have strictly increasing ends with no contained pair; the problem reduces to a longest chain-like selection. Removing every interval that contains some other interval is too many removals.

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

Exams that ask this topic