Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
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 pairwise disjoint?
- A. 2
- B. 3
- C. 4
- D. 1
Correct answer: A. 2
Keep the maximum disjoint set and remove the rest; with half-open intervals a touching pair such as [0,2) and [2,4) is compatible. The answer is the number of intervals minus the size of the best kept set.
More Coding Interview Problems questions
- Array a = [2, 3, 5, 1, 4, 5, 2, 3]. How many contiguous subarrays have an even length and a sum divisible by 5?
- In the binary string "1101001100", find the length of the longest substring that has equally many 0s and 1s and whose length is a multiple…
- Values [1, 9, 4, 12, 7, 15, 3]. How many unordered pairs of distinct positions have an absolute difference of at least 5?
- How many subsets of {1, 2, ..., 12} have a sum of exactly 20?
- How many integers x with 1 <= x <= 200 have an odd number of 1-bits in their binary representation?
- Meetings (closed-open as half-open intervals) are [1,4), [1,4), [2,6), [5,8), [3,9), [7,10). A room can be reused the moment a meeting…