Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Balloons are closed horizontal intervals [10,16], [2,8], [1,6], [7,12]. One vertical arrow at x bursts every balloon whose interval contains x, endpoints included. What is the minimum number of arrows needed?
- A. 3
- B. 4
- C. 1
- D. 2
Correct answer: D. 2
Greedy: sort by right end and shoot at the earliest end; every balloon that starts at or before that point is burst too. The arrow at x = 6 bursts [1,6] and [2,8], and the other arrow at x = 12 bursts [7,12] and [10,16]; the answer is 2.
More Coding Interview Problems questions
- Half-open intervals [1,2), [2,3), [3,4) and [1,3) are given. What is the minimum number of intervals that must be removed so that the…
- Jobs are (start, end, profit) triples: (1,4,5), (3,5,1), (0,6,8), (4,7,4), (3,8,6), (5,9,3), (6,10,2), (8,11,4). One machine can run a set…
- 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…
- 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…