Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Closed intervals [1,3], [2,6], [3,5], [4,8], [7,9], [9,11], [10,12]. Two intervals conflict if they share any point, endpoints included. What is the largest number of pairwise non-conflicting intervals?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Sort by right endpoint and greedily take the next interval whose start is strictly greater than the last chosen end. Closed endpoints matter: [7,9] and [9,11] share the point 9 and conflict, which changes the count.
More Coding Interview Problems questions
- 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…
- 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?