Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Half-open intervals [1,6), [2,4), [3,8), [5,7), [6,9), [7,10) are given. What is the maximum number of intervals that contain a common time point?
- A. 3
- B. 4
- C. 5
- D. 6
Correct answer: A. 3
The answer is the peak overlap, found by sweeping the start and end events and keeping a running count; with half-open intervals, an interval ending at t does not cover t. Counting the intervals that start before the peak is not the same quantity.
More Coding Interview Problems questions
- Trains (arrival, departure) in minutes are (900,930), (940,1200), (950,1120), (1100,1130), (1500,1800), (1130,1140). A platform holds one…
- The half-open intervals [0,3), [2,5), [4,8) and [7,9) are given. What is the total length of their union (the number of unit-length cells…
- Intervals [1,6), [2,4), [3,8), [5,7), [6,9), [7,10) are given. How many unordered pairs of these intervals overlap (share at least one…
- Problem: Sum the minimum of every non-empty subarray of [3, 1, 2, 4] by brute force. python a = [3, 1, 2, 4] print(sum(min(a[i:j + 1]) for…
- Problem: Count inversions in [2, 4, 1, 3, 5] with a Fenwick tree over the values. python def inv(a): n = max(a) t = [0] (n + 1) def…
- Problem: Run Bellman-Ford style negative-cycle detection (all distances start at 0, V - 1 rounds, then one extra check) on 3 vertices with…