Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Closed intervals [1,4], [2,6], [5,8], [7,9], [8,12], [10,11] must each contain at least one chosen integer point. What is the minimum number of points needed?
- A. 4
- B. 5
- C. 3
- D. 2
Correct answer: C. 3
Sort by right endpoint and place a point at the right end of the first unhit interval; every interval containing that point is hit. This matches the count of greedy disjoint intervals, where two intervals share a point exactly when they overlap.
More Coding Interview Problems questions
- Jobs are triples (start, end, weight): (1,3,2), (2,5,4), (4,6,3), (6,8,5), (5,9,6). Jobs may be chosen together only when one ends no…
- Array a = [2, 1, 3, 4, 1, 2, 5, 1]. How many non-empty contiguous subarrays contain exactly as many odd numbers as even numbers?
- Array a = [4, -1, 2, -3, 5, -2, 1, 1, -4]. How many DISTINCT values appear among the sums of all non-empty contiguous subarrays?
- Array a = [6, 1, 8, 3, 9, 4, 2, 7, 5] has distinct values. How many ordered pairs (i, j) with i != j satisfy a[i] - a[j] = 4?
- For a = [1, 2, 3, 4, 5, 6, 7, 8], how many contiguous subarrays have a sum that is a multiple of 5?
- Array a = [2, 1, 5, 2, 3, 1, 4] has only positive values. How many non-empty contiguous subarrays have sum at most 9?