What is the main goal of the Minimum Number of Platforms problem?
To find the least number of train platforms required at a station so that no train has to wait for another to leave.
Click to reveal answer
intermediate
Which data structures are commonly used to solve the Minimum Number of Platforms problem efficiently?
Two sorted arrays (one for arrival times and one for departure times) and pointers to traverse them.
Click to reveal answer
intermediate
Explain the two-pointer technique used in the Minimum Number of Platforms problem.
Use one pointer to track arrivals and another for departures. Increment platform count when a train arrives before the earliest departure, else decrement when a train departs.
Click to reveal answer
beginner
Why do we sort arrival and departure times separately in the Minimum Number of Platforms problem?
Sorting helps to process events in chronological order, making it easier to count overlapping trains and platforms needed.
Click to reveal answer
beginner
What does the maximum value of platforms needed during the traversal represent?
It represents the minimum number of platforms required so that no train waits.
Click to reveal answer
What is the first step in solving the Minimum Number of Platforms problem?
ACalculate total travel time
BCount total trains
CAssign platforms randomly
DSort arrival and departure times separately
✗ Incorrect
Sorting arrival and departure times separately allows us to process events in order.
When do we increase the platform count during traversal?
AWhen a train arrives before the earliest departure
BWhen no trains are at the station
CWhen trains arrive and depart at the same time
DWhen a train departs before the next arrival
✗ Incorrect
We increase platform count when a train arrives before the earliest train departs, indicating overlap.
What does decrementing the platform count signify in the algorithm?
AA train has departed
BA train has arrived
CA platform is broken
DA train is delayed
✗ Incorrect
Decrementing means a train has left, freeing a platform.
What is the time complexity of the efficient solution for Minimum Number of Platforms?
AO(n^2)
BO(n)
CO(n log n)
DO(log n)
✗ Incorrect
Sorting takes O(n log n), and traversal is O(n), so overall O(n log n).
If arrival times are [9:00, 9:40, 9:50] and departure times are [9:10, 12:00, 11:20], what is the minimum number of platforms needed?
A1
B2
C3
D4
✗ Incorrect
At 9:50, two trains overlap, so 2 platforms are needed.
Describe the step-by-step approach to find the minimum number of platforms needed for trains arriving and departing at different times.
Think about how to count overlapping trains using sorted times.
You got /6 concepts.
Explain why sorting arrival and departure times separately is crucial in solving the Minimum Number of Platforms problem.
Consider how events happen over time at the station.
You got /4 concepts.
Practice
(1/5)
1. What does the problem "Minimum Number of Platforms" ask you to find given train arrival and departure times?
easy
A. The earliest train arrival time
B. The minimum number of platforms needed so no train waits
C. The total number of trains arriving in a day
D. The maximum number of trains arriving at the same time
Solution
Step 1: Understand the problem goal
The problem asks for the minimum number of platforms required so that no train has to wait for another to leave.
Step 2: Clarify what is being counted
We count how many trains overlap in time, which determines how many platforms are needed simultaneously.
Final Answer:
The minimum number of platforms needed so no train waits -> Option B
Quick Check:
Minimum platforms = max trains overlapping [OK]
Hint: Count overlapping trains to find minimum platforms needed [OK]
Common Mistakes:
Confusing total trains with platforms needed
Ignoring overlapping times
Counting only arrivals or departures
2. Which of the following C code snippets correctly declares arrays for train arrival and departure times for 5 trains?
easy
A. int arrival[5] = {900, 940, 950, 1100, 1500}; int departure[5] = {910, 1200, 1120, 1130, 1900};
B. int arrival = {900, 940, 950, 1100, 1500}; int departure = {910, 1200, 1120, 1130, 1900};
C. int arrival[5] = (900, 940, 950, 1100, 1500); int departure[5] = (910, 1200, 1120, 1130, 1900);
D. int arrival[] = 900, 940, 950, 1100, 1500; int departure[] = 910, 1200, 1120, 1130, 1900;
Solution
Step 1: Check array declaration syntax in C
Arrays must be declared with size or empty brackets and initialized with curly braces {}.
Step 2: Validate each option
int arrival[5] = {900, 940, 950, 1100, 1500}; int departure[5] = {910, 1200, 1120, 1130, 1900}; uses correct syntax with size and braces. Others use incorrect syntax like parentheses or missing braces.
Final Answer:
int arrival[5] = {900, 940, 950, 1100, 1500}; int departure[5] = {910, 1200, 1120, 1130, 1900}; -> Option A
Quick Check:
Arrays use {} with size or empty brackets [OK]
Hint: Use curly braces {} to initialize arrays in C [OK]
Common Mistakes:
Using parentheses () instead of braces {}
Missing array size or empty brackets
Assigning values without braces
3. Given arrival times {900, 940, 950, 1100, 1500} and departure times {910, 1200, 1120, 1130, 1900}, what is the minimum number of platforms needed? Consider the following code snippet:
int arrival[] = {900, 940, 950, 1100, 1500};
int departure[] = {910, 1200, 1120, 1130, 1900};
int n = 5;
// Assume arrays are sorted
int i = 1, j = 0, platforms = 1, result = 1;
while (i < n && j < n) {
if (arrival[i] <= departure[j]) {
platforms++;
i++;
if (platforms > result) result = platforms;
} else {
platforms--;
j++;
}
}
printf("%d", result);
medium
A. 4
B. 2
C. 1
D. 3
Solution
Step 1: Trace the platform count with given times
Starts platforms=1 (900 arrival), i=1, j=0. 940 <= 910? No, so platforms--, j=1. Then 940 <= 1200: platforms++, i=2. 950 <= 1200: platforms++, i=3. 1100 <= 1200: platforms++, i=4 (max=3). Later departures reduce platforms.
Step 2: Find max platforms during iteration
Maximum platforms reached is 3 (trains 940-1200, 950-1120, 1100-1130 overlap).
Final Answer:
3 -> Option D
Quick Check:
Max overlapping trains = 3 [OK]
Hint: Sort times and count overlaps to find max platforms [OK]
Common Mistakes:
Not sorting arrival and departure arrays
Incorrectly incrementing or decrementing platform count
Confusing <= with < in comparisons
4. Identify the error in the following code snippet for calculating minimum platforms:
int arrival[] = {900, 940, 950, 1100, 1500};
int departure[] = {910, 1200, 1120, 1130, 1900};
int n = 5;
int i = 0, j = 0, platforms = 0, result = 0;
while (i < n && j < n) {
if (arrival[i] < departure[j]) {
platforms++;
i++;
if (platforms > result) result = platforms;
} else {
platforms--;
j++;
}
}
printf("%d", result);
medium
A. No error, code is correct
B. Initialization of platforms should start at 1
C. Loop condition should be i <= n && j <= n
D. Comparison should be arrival[i] <= departure[j]
Using arrival[i] <= departure[j] (overcounts on equal times)
Initializing platforms=1 with i=0 (overcounts first arrival)
Loop i <= n && j <= n (off-by-one)
5. You have arrival times {900, 940, 950, 1100, 1500, 1800} and departure times {910, 1200, 1120, 1130, 1900, 2000}. How would you modify the algorithm to handle trains arriving and departing at the same time (e.g., arrival[i] == departure[j]) to minimize platforms needed?
hard
A. Ignore trains with equal arrival and departure times
B. Treat arrival[i] == departure[j] as arrival first to allocate platform
C. Treat arrival[i] == departure[j] as departure first to free platform
D. Increase platform count by 2 when times are equal
Solution
Step 1: Understand impact of equal arrival and departure times
If a train departs at the same time another arrives, the platform can be reused without adding a new one.
Step 2: Adjust comparison logic
When arrival[i] == departure[j], count departure first to free platform before arrival increments platform count.
Final Answer:
Treat arrival[i] == departure[j] as departure first to free platform -> Option C
Quick Check:
Departure before arrival frees platform [OK]
Hint: Count departures before arrivals when times are equal [OK]
Common Mistakes:
Counting arrival before departure causing extra platform
Ignoring equal times leading to wrong count
Adding platforms unnecessarily
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.