Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Closed integer intervals [1,3], [2,5], [4,7], [6,9], [8,10], [5,6] are available. What is the minimum number needed so that every integer from 1 to 10 lies in at least one chosen interval?
- A. 4
- B. 5
- C. 3
- D. 2
Correct answer: C. 3
Greedy cover: from the leftmost uncovered integer, pick the interval containing it that reaches furthest right, and repeat. Brute force over subsets of the six intervals confirms the minimum.
More Coding Interview Problems questions
- Array [3, 1, 2, 5, 0, 4, 2]. How many contiguous subarrays have a sum equal to twice their length?
- Array [1, 3, 5, 4, 2, 6, 8, 7, 9]. What is the length of the shortest contiguous segment that, once sorted, makes the whole array sorted?
- How many permutations of (0, 1, 2, 3) have exactly one position i with p[i] = i?
- Arrays A = [2, 5, 3, 7] and B = [4, 6, 1, 9]. How many pairs (x from A, y from B) satisfy 10 <= x y <= 40?
- Trains arrive at 100, 140, 150, 180, 200 and depart at 120, 160, 190, 210, 230 (times are not paired). A platform holds one train at a…
- Array [1, 2, 1, 3, 2, 2]. How many contiguous subarrays contain exactly two distinct values?