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?
- A. 2
- B. 3
- C. 1
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many non-empty contiguous subarrays of [1, -1, 2, 0, 1, 3, -2, 1] have a sum equal to their length (number of elements)? Transform…
- Choose any subset of the positions of [4, -2, 7, 3, 9, 1, -5, 8, 2] (possibly empty) so that every two chosen positions are at least 3…
- Assertion (A): Dynamic programming over subsets for TSP needs exponential time in the number of cities. Reason (R): The number of subsets…
- Assertion (A): Kadane's algorithm can be used to find the maximum subarray sum in O(n) time. Reason (R): It keeps the best sum ending at…
- Assertion (A): Binary search on the answer requires that the feasibility predicate is monotone. Reason (R): Only a monotone predicate lets…
- Assertion (A): The greedy 'largest coin first' is optimal for the coin set {1, 3, 4} when the amount is 6. Reason (R): A coin system whose…