At an airport, you have a timetable for arrivals and departures. You need to determine the minimum number of gates you’d need to provide so that all the planes can be placed at a gate as per their schedule.
The arrival and departure times for each plane are presented in two arrays, sorted by arrival time, and you’re told the total number of flights for the day. Assume that no planes remain overnight at the airport; all fly in and back out on the same day. Assume that if a plane departs in the same minute as another plane arrives, the arriving plane takes priority (i.e. you'll still need the gate for the departing plane); Write a function that returns the minimum number of gates needed for the schedules you're given.
Example:
arr = {900, 940, 950, 1100, 1500, 1800}
dep = {910, 1200, 1120, 1130, 1900, 2000}
flights = 6
In this example the return value should be 3 since the schedules for at most 3 planes overlap.
Arrive 9:00 ; 1 gate
Depart 9:10 ; 0 gates
Arrive 9:40 ; 1 gate
Arrive 9:50 ; 2 gates
Arrive 11:00 ; 3 gates
Depart 11:20; 2 gates
Depart 11:30 ; 1 gate
Depart 12:00 ; 0 gates
Arrive 15:00 ; 1 gate
Arrive 18:00 ; 2 gates
Depart 19:00 ; 1 gate
Depart 20:00 ; 0 gates