Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Intervals [0,4], [3,7], [6,10], [2,6], [9,12], [1,3] are available. What is the minimum number of them needed to cover the whole segment [0, 10], meaning every point x with 0 <= x <= 10 lies in some chosen interval?
- A. 4
- B. 6
- C. 3
- D. 5
Correct answer: C. 3
Repeatedly extend the covered prefix: among intervals starting at or before the current reach, pick the one that ends furthest right. Choosing by shortest length or counting every interval that touches the segment gives different totals.
More Coding Interview Problems questions
- Problem: A directed road map has junctions 0..4 and roads (u, v, w): (0,1,1), (0,2,1), (1,3,1), (2,3,1), (3,4,1), (1,2,1). Count the…
- Problem: A grid of 0/1 costs (a cell costs its value when you enter it) is solved by 0-1 BFS from the top-left cell to the bottom-right…
- Problem: Junctions 1..6 form a precedence graph with edges 4 to 1, 3 to 1, 2 to 5 (an edge a to b means a must come before b). Kahn's…
- Problem: Kruskal's algorithm with union-find is run on 5 nodes (0..4) with weighted edges (4,0,1), (1,1,2), (3,0,2), (2,2,3), (7,3,4)…
- Problem: Count the subsets (including the empty subset) of {1, 2, 3, 4, 5, 6} whose sum is divisible by 3. python a = [1, 2, 3, 4, 5, 6]…
- Problem: How many integers x with 1 <= x <= 100 have no two adjacent equal decimal digits? Use the rule that a one-digit number always…