Data Structures & AlgorithmsVery hardICPC regional · greedy theory
Problem: Which statement about the greedy algorithm for 'minimum number of lecture rooms' (interval partitioning) is correct?
- A. The answer is always the number of intervals
- B. Sorting by length gives the optimum
- C. Sorting by start time and reusing the room that frees earliest uses exactly the maximum overlap number of rooms
- D. The answer equals the minimum number of overlapping intervals at any point
Correct answer: C. Sorting by start time and reusing the room that frees earliest uses exactly the maximum overlap number of rooms
The number of rooms needed equals the maximum number of intervals alive at once, and the start-time greedy achieves it. Using the minimum overlap is the trap.
More Coding Interview Problems questions
- Problem: Which statement about bitmask DP for a Hamiltonian path problem on n = 20 vertices is correct in the standard sense?
- Problem: Which claim about a binary search over a rotated sorted array (no duplicates) finding the minimum element is correct?
- Problem: How many pairs (i < j) of a = [1, 2, 4, 5, 7, 8] have a[i] - a[j] divisible by 3? Run the code. python a = [1, 2, 4, 5, 7, 8]…
- Problem: What is the minimum number of meeting rooms needed for intervals [0,30], [5,10], [15,20]? Run the sweep-line code. python iv =…
- Problem: How many inversions (pairs i < j with a[i] > a[j]) does a = [2, 0, 2, 1, 1, 0] have? Run the code. python a = [2, 0, 2, 1, 1, 0]…
- Problem: How many integers x in [1, 50] are perfect sixth powers (x = y^6 for an integer y)? Run the code. python print(sum(1 for x in…