this has proven to be a challenging task for me so would really appreciate any help:
We have two columns in a data frame: start_time
, end_time
(both object type hh:mm:ss) which I converted into seconds (float64).
An example of our data (out of 20000 rows):
start_time=["00:01:14", "00:01:15", "00:01:30"]
end_time=["00:01:39", "00:02:25", "00:02:10"]
I am running the following code, but I am not convinced it's correct:
def findMaxPassengers(arrl, exit, n):# define function
arrl.sort() # Sort arrival and exit arrays
exit.sort()
passengers_in = 1
max_passengers = 1
time = arrl[0]
i = 1
j = 0
while (i < n and j < n):
if (arrl[i] <= exit[j]): # if the next event in sorted order is an arrival, then add 1
passengers_in = passengers_in + 1
# Update max_passengers if needed
if(passengers_in > max_passengers):
max_passengers = passengers_in
time = arrl[i]
i = i + 1
else:
passengers_in = passengers_in - 1
j = j + 1
print("Maximum Number of passengers =", max_passengers, "at time", time)
df = pd.read_excel("Venue_Capacity.xlsx")
arrl = list(df.loc[:,"start_time"]);
exit = list(df.loc[:,"end_time"]);
n = len(arrl);
findMaxPassengers(arrl, exit, n);
Is the thinking/code structure behind it correct?
I am not sure if the way the code&time works, if it's adding 1 or subtracting one correctly. The code is running ok and is giving out:
Maximum Number of Passengers = 402 at time 12:12:09
but I am unable to check a dataset of 20000+ rows.