Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Closed intervals [1,3], [3,5], [2,4], [5,7], [6,8] are given. Two intervals conflict if they share any point, endpoints included. What is the maximum number of pairwise non-conflicting intervals?
- A. 3
- B. 2
- C. 4
- D. 1
Correct answer: B. 2
Sort by right endpoint and take an interval when its start is strictly after the last chosen end, since touching endpoints conflict for closed intervals. Allowing touching ends (start equal to the last end) overcounts, which is the trap.
More Coding Interview Problems questions
- Meetings are the half-open intervals [0,30), [5,10), [15,20), [10,15), [20,25); a room can host a new meeting starting exactly when…
- Balloons are closed horizontal intervals [10,16], [2,8], [1,6], [7,12]. One vertical arrow at x bursts every balloon whose interval…
- Half-open intervals [1,2), [2,3), [3,4) and [1,3) are given. What is the minimum number of intervals that must be removed so that the…
- Jobs are (start, end, profit) triples: (1,4,5), (3,5,1), (0,6,8), (4,7,4), (3,8,6), (5,9,3), (6,10,2), (8,11,4). One machine can run a set…
- Intervals [0,4], [3,7], [6,10], [2,6], [9,12], [1,3] are available. What is the minimum number of them needed to cover the whole segment…
- Problem: A directed road map has junctions 0..4 and roads (u, v, w): (0,1,1), (0,2,1), (1,3,1), (2,3,1), (3,4,1), (1,2,1). Count the…