Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Half-open intervals [0,4), [1,3), [2,6), [5,7), [6,9), [8,10). What is the minimum number of integer points such that every interval contains at least one of the chosen points?
- A. 4
- B. 3
- C. 5
- D. 2
Correct answer: B. 3
Stabbing: sort by right end and pick a point at the right end of the first interval that is not yet hit. For half-open intervals the chosen point must lie strictly before the end, so the last integer of each interval is the point to use.
More Coding Interview Problems questions
- Tasks are (deadline, duration): (3, 1), (2, 2), (4, 3), (5, 2), (1, 1). Tasks run one after another from time 0 without preemption, and a…
- Split the array [7, 2, 5, 10, 8, 4, 6] into 3 non-empty contiguous parts so that the largest part sum is as small as possible. What is…
- Sorted arrays A = [1, 4, 6, 9] and B = [2, 3, 7, 10]. How many pairs (x from A, y from B) have 8 <= x + y <= 12?
- Array a = [1, 2, 3, 1, 2, 3, 1]. How many contiguous subarrays of length at least 2 have the sum of the elements at even offsets (0, 2, 4…
- Array [1, 2, 3, 4, 5, 6, 7, 0]. How many index pairs i < j satisfy (a[i] OR a[j]) = 7?
- Coins have values 1, 3, 9, 27, 81, ... (powers of three, unlimited supply). What is the minimum number of coins needed to pay exactly 41?