Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Trains arrive at 100, 140, 150, 180, 200 and depart at 120, 160, 190, 210, 230 (times are not paired). A platform holds one train at a time, and a train arriving exactly when another departs may use the platform. What is the minimum number of platforms?
- A. 3
- B. 1
- C. 5
- D. 2
Correct answer: D. 2
Merge the sorted arrival and departure lists: process a departure before an arrival only when it is not later. Pairing trains in input order is not required; the sweep uses the sorted lists independently.
More Coding Interview Problems questions
- Array [1, 2, 1, 3, 2, 2]. How many contiguous subarrays contain exactly two distinct values?
- Sorted arrays [2, 6, 9, 14] and [4, 7, 11, 15] are merged into one list. How many elements of the merged list lie strictly between 5 and 12?
- Choose a from {6, 9, 12} and b from {3, 5, 10}. What is the largest possible value of a XOR b?
- Tasks AAABBC must be scheduled one per time unit; two identical tasks need at least 2 idle-free units between them (cooldown k = 2, i.e…
- Half-open intervals [1,5), [3,8), [10,12), [11,15). How many integer points lie in at least one of these intervals?
- Array [5, -5, 2, 3, -2, 7, 3]. How many contiguous subarrays have a sum that is 0, 5 or 10?