Created
November 21, 2019 17:52
-
-
Save venelrene/f2e6c4148bb6140e1a96957d4804383c to your computer and use it in GitHub Desktop.
There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def queue_time(customers, n) | |
| registers = Array.new(n, 0) | |
| while !customers.empty? | |
| idx = registers.index(registers.min) | |
| registers[idx] += customers.shift unless customers.empty? | |
| end | |
| registers.max | |
| # if I had to do it in one line | |
| # customers.each{|time| registers[registers.index(registers.min)] = (time + registers.min)} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment