question archive you will be making a function that will find the least number of gates that need to be in use in order for the day's airport operations to run smoothly

you will be making a function that will find the least number of gates that need to be in use in order for the day's airport operations to run smoothly

Subject:Computer SciencePrice: Bought3

you will be making a function that will find the least number of gates

that need to be in use in order for the day's airport operations to run smoothly. You will be given a list of departure times and arrival times of aircraft for a day, and asked to return the maximum number of gates in use that day.
Your function will receive two python lists of floats. One will represent departure times and one will represent arrival times. A float represents the amount of time (in seconds) after midnight on that day.
Modify the following functions
gates_needed(departures: List[float], arrivals: List[float]) -> int

-departures: List[float]: A python list of floats containing departure times of flights at the airport
-arrivals: List[float]: A python list of floats containing arrival times of flights at the airport
-Return: An integer that represents the maximum number of gates needed at any point during the day of these departures and arrivals
-Time Complexity: O(n + m), where n is the length of departures and m is the length of arrivals
-Space Complexity: O(n + m) 
Guarantees

-There will never be a more departures than arrivals at the airport (no negative gates)
-The first arrival will happen before the first departure
-The amount of gates used leftover from the previous night will always be 0Notes

-You may NOT have more than max(len(departures), len(arrivals)) in any structure at any given time. Think about what kind of data structure may be useful to solve this problem. You can use multiple of them
-You might want to use Queue.SimpleQueue
-Recall use of pop(0 on a Python list) is O(n), using it will more than likely violate time complexity!
-The first plane to arrive will also be the first to depart
-If a plane has the same departure time as its arrival time, you can assume the plane performed a "touch-and-go", and didn't need a gateExamples:
Ex 1:
departures = [1, 5, 8, 20]
arrivals = [0, 1.5, 3, 19]
Return: 2. The time frame where most planes are ever on the ground is between time 3 and time 5. A plane arrives at 0 and then leaves at 1. At this point, only one gate had to be staffed. A plane arrives at 1.5 and another at 3. Now, two gates have to be staffed on this day. The first of these two flights leaves at 5 and the other at 8. With no gates in use, a plane arrives at 19 and then leaves at 20.
 
Ex 2:
departures = [1, 5, 8, 20]
arrivals = [0, 1.5, 3, 19, 21, 21.5, 22, 22.5, 23, 23.5]
Return: 6. At the end of the night, 6 planes are on the ground at the airport, that means that 6 gates had to be in use, which is the maximum number over the day.

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE