Ad
  • Custom User Avatar

    In my opinion, this scenario is like a supermarket checkout situation. You would always choose to go to an empty checkout lane, or if all are occupied, you'd pick the lane with the shortest wait time. That's why the function call queueTime(std::vector{2,3,10}, 2) should return 12, not 10.

  • Custom User Avatar

    I have tried something similar (but less elegant), however this algorithm does not pass the test with the dataset:

    customers {100, 90, 90, 60, 50}
    n 2

    this algorithm return 210 (100+60+50 = 210 vs 90 + 90 =180)
    but true result: 200 (100 + 90 = 190 vs 90 + 60 + 50 = 200)

  • Custom User Avatar

    correct me, if i am wrong. This solution takes n^2 running time due to for each customer, this program is finding the register by checking each register's least. Space-wise, it is O(n) where the n is the number of registers.

  • Custom User Avatar

    There are specifications:

    input customers: an array of positive integers representing the queue.

    So a (silly and absurd) input of a negative queue will never happen.

  • Custom User Avatar

    Very nice! However, it will crash when (n <= 0).

  • Custom User Avatar

    it is so beautiful and I am superised that my code is similar to this solusion ,I'm just a noob guy here XD

  • Custom User Avatar

    For those unfamiliar, the problem is also known as "Bin Packing". I was very suprised but the simplicity of solution, when I first heard about it as well :D