Challenge 4: Find Minimum Number of Platforms Required for a Train Station
Given arrival and departure times of trains, calculate the number of platforms required for a train station.
We'll cover the following
Problem Statement
Implement a function that returns the minimum number of platforms that are required for the train so that none of them waits.
Input
Two arrays which represent arrival and departure times of trains that stop
Output
Minimum number of platforms required
Sample Input
Arrival Time | Departure Time |
---|---|
9:00 | 9:10 |
9:40 | 12:00 |
9:50 | 11:20 |
11:00 | 11:30 |
15:00 | 19:00 |
18:00 | 20:00 |
// arrival[] = {900, 940, 950, 1100, 1500, 1800};
// departure[] = {910, 1200, 1120, 1130, 1900, 2000};
// n = sizeof(arrival) / sizeof(arrival[0]);
Sample Output
Minimum platforms needed = 3
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.