Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft
Trains occupy a platform from arrival to departure INCLUSIVE, so a train arriving at the same minute another departs needs a separate platform. Times are in minutes after 9:00: [25, 55], [50, 70], [60, 90], [70, 115], [110, 120], [130, 140], [145, 165]. Sorting arrivals and departures and sweeping with two pointers, what is the minimum number of platforms?
- A. 2
- B. 3
- C. 4
- D. 5
Correct answer: B. 3
With inclusive occupancy, an arrival at time t must be processed before a departure at the same t. The running count then peaks at 3. Processing departures first at ties (the exclusive convention) gives 2.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Which statement about the KMP failure (lps) array of a pattern of length m is correct?
- Find the leaders (elements strictly greater than everything to their right) by scanning from the right. What is printed? python a = [18…
- Integer square root by binary search (largest m with m·m ≤ n). What is printed (root, iterations)? python n, lo, hi, it = 200, 0, 200, 0…
- Items E, F, G, H, I, J are pushed onto an empty stack in this order, and a pop may happen at any time. Which pop order is NOT possible?
- Exponential search: double the bound i (1, 2, 4, …) until a[i] ≥ key or i passes the end, then binary-search the last range. How many…
- One Hoare partition with the FIRST element as pivot (i moves right while a[i] < pivot, j moves left while a[j] > pivot, swap while i < j…