1

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.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Jack Ryan
  • 11
  • 4
  • 1
    Have you tried running/testing it? (Are you able to?) – Quaris Jan 12 '23 at 00:27
  • The code formatting has gotten messed up. Please [edit] to fix it. As well, the input data needs to be provided as text, [not a picture](https://meta.stackoverflow.com/q/285551/4518341), and you should include your output for completeness too. For more info, see [mre], and for specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341). – wjandrea Jan 12 '23 at 00:28
  • 1
    Have you tried maybe doing the calculation by hand and seeing if your code matches it? – wjandrea Jan 12 '23 at 00:29
  • It's giving an output, but given it's 20000 rows I can't really double check it. Wondering if someone could run this with any other data? – Jack Ryan Jan 12 '23 at 00:53
  • Beside the point, but get rid of the semicolons. They do nothing there. – wjandrea Jan 12 '23 at 17:32
  • Maybe this is beside the point, but you said the data type is float64, but the output seems to be a string (or a time) – wjandrea Jan 12 '23 at 17:36
  • To be clear, if there are multiple maxima, you only need to find the first one, right? – wjandrea Jan 12 '23 at 17:38

0 Answers0