Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
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?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Sweep over the points: the answer is the peak count of intervals covering one point. Closed intervals include both endpoints, so the point 4 is covered by [1,4], [2,6] and [4,7].
More Coding Interview Problems questions
- 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 +…
- Array [1, 2, 4, 1, 3, 4]. How many contiguous subarrays have a bitwise OR of exactly 7?
- Set A = {1, 2, 4, 7} and set B = {3, 5, 6, 8}. Choose two different elements from A and two different elements from B. How many choices…
- Half-open intervals [0,2), [1,3), [2,4), [3,5), [4,6). What is the minimum number of intervals to remove so the remaining intervals are…