Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Trains arrive at [900, 940, 950, 1100, 1500, 1800] and depart at [910, 1200, 1120, 1130, 1900, 2000] (matched train by train). A platform serves one train at a time, and a train arriving at the moment another departs can use the same platform. What is the minimum number of platforms?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Sort arrivals and departures separately and sweep: process an arrival before a departure only when the arrival is strictly earlier, so an equal time frees a platform first. The peak count of simultaneously present trains is the answer.
More Coding Interview Problems questions
- Problem: Children stand in a line with ratings [1, 0, 2]. Each child gets at least one candy, and a child with a higher rating than a…
- Problem: Water is poured into a container of heights [1, 8, 6, 2, 5, 4, 8, 3, 7]. Choose two lines to maximise the area of water they…
- Problem: Trucks carry boxes: each truck type is (count, units per box), and at most 10 boxes fit on the truck. Maximise units per truck…
- Problem: How many contiguous subarrays of [1, 2, 3, 4, 5] have sum exactly 5? Run the code. python a = [1, 2, 3, 4, 5] print(sum(1 for i…
- Problem: What is the length of the longest zigzag subsequence (values alternate strictly up and down) of [1, 7, 4, 9, 2, 5]? Run the DP…
- Problem: Two piles of stones (values [1, 6, 11, 5]) are to be divided into two groups whose sums differ as little as possible. What is the…