There is a line for the self-checkout machines at the supermarket. Your challenge is to write a function that calculates the total amount of time required for the rest of the customers to check out!
customers : an array of positive integers representing the line. Each integer represents a customer, and its value is the amount of time they require to check out.
n : a positive integer, the number of checkout tills.
There is only one line serving many machines, and
The order of the line never changes, and
The front person in the line (i.e. the first element in the array/list) proceeds to a machine as soon as it becomes free.
The function should return an integer, the total time required.
queueTime([5,3,4], 1) // should return 12 // because when there is 1 machine, the total time is just the sum of the times queueTime([10,2,3,3], 2) // should return 10 // because here n=2 and the 2nd, 3rd, and 4th people in the // queue finish before the 1st person has finished. queueTime([2,3,10], 2) // should return 12
Good luck, happy coding!
Want to propose a challenge idea for a future post? Email firstname.lastname@example.org with your suggestions!