Ad
  • Custom User Avatar

    Thanks those who have helped explain the kata!
    @arssonist, I can't really give any explicit hints or it will ruin the fun of completing the kata... ;)

  • Custom User Avatar

    But how do U do this? Reasoning it out is not that hard, but knowing how to make the code do it is another.

    Any concrete hints? Not explanation about the basics of the problem. (I realize this question was not answered for me but still, thought I'd try and get some info anyway)

  • Custom User Avatar

    You don't have to be CS guy to understand this. Let's check the 1st case queue_time([5, 3, 4], 1)

    Imagine [5, 3, 4] is the costumers who want to go to checkout's queue. The 1st person need 5s, the 2nd person need 3s, and the last one need 4s.

    The number 1 is n, which its mean the number of queue.

    This is the scenario:

    1. The 1st person goes into queue 1, since nobody in there.
    2. The 2nd person needs to wait 1st person, because the queue's only 1. After 1st person finish, the 2nd person can go replace him/her.
    3. The 3rd person also needs to wait 2nd person. After 2nd person finish, the 3rd person can procced the checkout.

    The total time? 5 + 3 + 4 = 12.

    Now, let's take a look at 2nd case: [10, 2, 3, 3], 2

    This is the scenario:

    1. The 1st person goes into 1st queue. BUT the 2nd person could go to 2nd queue right? Why? Because it's empty and it will took longer time to checkout if he/she waits the 1s person in the 1st queue.
    2. Now, 2s elapsed, The 2nd person is finished, but the 1st person isn't. So, what the 3rd person do? ...
    3. Now, 5s elapsed, The 3rd person is finish, but the 1st person is still not finish yet. So, what the 4rd person do? ...
    4. Now, 8s elapsed, The 4th person is finish, but the 1st person is still arguing about the fish price (just kidding). But there's no people in waiting list, so the 2nd queue is empty.
    5. Finally, after 10s elapsed, the 1st person is finished.
      Total time? 10s

    How about the 3rd case?

    Well, you can guess actually. By judging the number, you can see that the 1st person and the 3rd person will eventually goes into the same queues.

    So, the total time is 12s.

    I hope this help!

  • Default User Avatar

    You should return with your function how long it will take for all the customers to check out. The first argument will bring you a list of how long each client will take. The second argument will tell the amount of queues available.