Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Half-open intervals [1,4), [2,6), [3,5), [5,8), [7,9), [8,10) are given. What is the largest number of them you can select so that no time point lies in more than two selected intervals?
- A. 6
- B. 5
- C. 4
- D. 3
Correct answer: B. 5
Brute force over all 64 selections checks the peak depth of each one; the answer is the largest selection whose peak depth is at most 2. A selection rule that only looks at the earliest end can exceed the depth limit.
More Coding Interview Problems questions
- Meetings are closed-open intervals [1,3), [2,5), [4,6), [5,7), [6,9), [8,10) and one room can hold one meeting at a time. A meeting may…
- Sprinklers at positions p with radius r cover the closed interval [p - r, p + r] of a garden. The sprinklers are (1,2), (4,1), (7,3)…
- Jump game: array a = [2, 3, 1, 1, 4, 2, 1, 3, 1, 2]. Starting at index 0, from index i you may jump forward to any index between i+1 and…
- Packages with weights [6, 2, 8, 4, 5, 3, 7, 1, 9] must be shipped in order using at most 3 days, each day loading a contiguous block of…
- What is the minimum number of swaps of two arbitrary elements needed to sort the array [3, 1, 4, 2] into increasing order?
- Given the numbers 3, 30, 34 and 5, arrange them in some order and concatenate the decimal strings. What is the largest number that can be…