Data Structures & AlgorithmsVery hardGATE CS · DSA
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: [15, 75], [70, 115], [75, 85], [100, 120], [120, 140], [130, 160], [145, 165]. Sorting arrivals and departures and sweeping with two pointers, what is the minimum number of platforms?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 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
- Counting sort on [1, 1, 2, 1, 0, 3, 3, 0, 2, 0] (values 0–4) builds count[], turns it into cumulative counts, then scans the input from…
- What is the length of the shortest contiguous subarray of [1, 3, 1, 8, 7, 3, 4, 7, 1, 2] whose sum is at least 20? (All values are…
- Count zero-sum contiguous subarrays with a prefix-sum frequency map. What is printed? python from collections import defaultdict a = [0…
- Rotate a square matrix 90° clockwise in place by transposing and then reversing each row. What is printed? python m = [[1, 2, 3], [4, 5…
- For the binary array [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1], replace 0 by −1 and use prefix sums with a first-occurrence map. What is the…
- Which application does NOT naturally use a stack?