Data Structures & AlgorithmsVery hardICPC regional · GATE CS
Intervals [(1, 3), (2, 5), (4, 6), (3, 4), (6, 8), (5, 7)] are closed integer ranges. Choose as many as possible so that every integer point is covered by at most 2 of the chosen intervals. What is the maximum number chosen?
- A. 4
- B. 2
- C. 6
- D. 5
Correct answer: A. 4
Subset enumeration on six intervals is the reference; a sweep with a multiset of current overlaps and an exchange argument gives the same answer at scale. Sorting by end time and taking any interval that does not overload a point is the greedy for the 'at most 1' case; the 'at most 2' case needs the overlap count, not just disjointness.
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
- Closed real intervals [(1, 4), (3, 6), (8, 9), (9, 12), (14, 15)] are merged whenever they overlap (sharing an endpoint counts as…
- Over all pairs of DIFFERENT positions of [2, 5, 3, 8, 4], take the product of each pair and sort all these products. What is the 6-th…
- Starting from [9, 6, 15, 4], repeat 3 times: take the current LARGEST element, replace it by its floor half, and keep the others. What is…
- How many substrings of "cbaebabacd" of length 3 are anagrams of "abc" (contain exactly the same letters with the same counts, in any order)?
- In "abababaabab", what is the maximum number of NON-OVERLAPPING occurrences of "aba" that can be chosen (left to right, each occurrence…
- A stack starts empty. The operations are ['push', 'push', 'pop', 'push', 'push', 'pop', 'push', 'push', 'push', 'pop', 'push']. How many…