Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Trains (arrival, departure) in minutes are (900,930), (940,1200), (950,1120), (1100,1130), (1500,1800), (1130,1140). A platform holds one train at a time and a train may leave as another arrives at the same minute. What is the minimum number of platforms needed?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Sort arrival and departure times separately and merge them, moving the pointer for the smaller time; a departure at the same minute as an arrival frees a platform first. The peak number of trains present at once is the answer.
More Coding Interview Problems questions
- 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…
- Problem: A directed graph has edges 0->1, 0->2, 1->2, 1->3, 2->3. Let A be its adjacency matrix. How many walks of exactly 3 edges go from…