(Solve in Dev c++) Given a schedule containing the arrival and departure time of trains in a station. Find the minimum number of platforms needed to avoid delay in any train’s arrival. The idea is to...


(Solve  in Dev c++)

Given a schedule containing the arrival and departure time of trains in a station. Find the minimum number of platforms needed to avoid delay in any train’s arrival.

The idea is to merge the arrival and deprature time of trains and consider them in sorted order. Maintain a counter to count the number of trains present at the station at any point. The counter also represents the total number of platforms needed at that time.



  • · If the train is scheduled to arrive next, increase the counter by one and update the minimum platforms needed if the count is more than the minimum platforms needed so far.



  • · If the train is scheduled to depart next, decrease the counter by 1.



One special case needs to be handled – when two trains are scheduled to arrive and depart simultaneously, depart the train first.


Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here