Data Structures & AlgorithmsHardCodeforces Div2 C · LeetCode-style
Intervals (inclusive integer ranges) are [(1, 3), (2, 5), (4, 9), (6, 7), (8, 12), (9, 10)]. What is the minimum number of intervals whose union covers every integer from 1 to 12?
- A. 4
- B. 1
- C. 5
- D. 3
Correct answer: D. 3
Greedy cover: from the first uncovered point, choose among intervals starting no later than it the one reaching farthest right, then repeat from one past that end. Choosing the first interval that covers the point (rather than the farthest) can need one extra interval.
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
- A binary string is "10110010". Flipping position i costs weight[i] = [3, 1, 4, 1, 5, 9, 2, 6]. You want the string to alternate (0101…
- How many contiguous subarrays of the binary array [1, 0, 1, 1, 0, 0, 1, 0] contain equally many 0s and 1s? (Non-empty subarrays only.)
- A string of brackets is ')))(()(' where '(' opens and ')' closes. What is the minimum number of brackets that must be removed to make the…
- How many elements of [2, 5, 1, 4, 3] have no strictly smaller element anywhere to their right?
- Three processes arrive at time 0 with bursts 5, 2 and 7. Round-robin uses quantum 3 and the queue starts as P1, P2, P3. Which process…
- A list holds 1 to 10 in order. All nodes whose value is prime are deleted. What is the sum of the remaining values?