Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Balloons span closed integer intervals [1,4], [2,3], [4,6], [5,8], [7,9]. One arrow shot at integer x bursts every balloon whose interval contains x. What is the minimum number of arrows?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Sort by right endpoint and shoot at the smallest end; every balloon starting at or before that point is burst by the same arrow. Shooting at the left endpoint of each balloon wastes arrows.
More Coding Interview Problems questions
- How many binary strings of length 6 contain neither two consecutive 0s nor three consecutive 1s?
- How many subsets (including the empty subset) of [3, 5, 9, 11, 14, 2] have a sum divisible by 7?
- Closed intervals [1,4], [2,6], [4,7], [5,9], [8,10] are given. What is the largest number of intervals that share a single integer point?
- Array [2, 8, 9, 18, 4, 16, 6, 3]. How many index pairs i < j have a[i] a[j] equal to a perfect square?
- Array [1, 2, 4, 3, 0, 5, 6]. What is the length of the longest contiguous subarray in which the XOR of the elements equals their sum?
- Ropes of lengths 4, 3, 2 and 6 are joined two at a time; joining ropes of lengths x and y costs x + y and creates one rope of length x +…