Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Closed intervals [0,3], [2,5], [4,8], [6,9], [8,12] are available. What is the minimum number of them needed so that every point of the set {1, 3, 4, 7, 8, 10} lies in at least one chosen interval?
- A. 3
- B. 4
- C. 5
- D. 2
Correct answer: A. 3
Choosing the longest intervals first is not optimal; a point-driven greedy picks the interval covering the leftmost uncovered point with the furthest right end. Brute force over small subsets confirms the minimum.
More Coding Interview Problems questions
- Closed intervals [1,6], [4,10], [5,5], [8,12], [2,3] are given. For the query points 5, 9 and 1, count how many intervals contain each…
- Piles of bananas [3, 6, 7, 11] must be eaten within H = 8 hours. Each hour you eat up to k bananas from one pile (a pile is finished in…
- Stalls at positions [1, 2, 4, 8, 9, 13] are available. Place 3 cows in distinct stalls so that the smallest distance between any two cows…
- Consider the bitmask DP that counts subsets of {1..n} with sum equal to S. For n = 4 and S = 5, what does the DP answer, counting the…
- Problem: A runner moves up, down, left or right one cell at a time on this 5×5 grid. '.' is open, '#' is a wall. The runner starts at (row…
- Problem: An undirected road network has 5 towns numbered 0 to 4 and these roads with lengths: 0–1 (7), 0–2 (2), 2–1 (3), 1–3 (1), 2–3 (8)…