6 kyu
The Supermarket Queue
5,787 of 54,403mattlub
Description:
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!
input
- customers: an array of positive integers representing the queue. 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.
output
The function should return an integer, the total time required.
Important
Please look at the examples and clarifications below, to ensure you understand the task correctly :)
Examples
queueTime([5,3,4], 1)
// should return 12
// because when there is 1 till, 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
Clarifications
- There is only ONE queue serving many tills, and
- The order of the queue NEVER changes, and
- The front person in the queue (i.e. the first element in the array/list) proceeds to a till as soon as it becomes free.
N.B. You should assume that all the test input will be valid, as specified above.
P.S. The situation in this kata can be likened to the more-computer-science-related idea of a thread pool, with relation to running multiple processes at the same time: https://en.wikipedia.org/wiki/Thread_pool
Arrays
Fundamentals
Similar Kata:
Stats:
Created | Aug 14, 2016 |
Published | Aug 14, 2016 |
Warriors Trained | 158172 |
Total Skips | 36656 |
Total Code Submissions | 302633 |
Total Times Completed | 54403 |
JavaScript Completions | 17258 |
Python Completions | 21582 |
Ruby Completions | 1562 |
C++ Completions | 3560 |
C# Completions | 3266 |
Java Completions | 5787 |
Haskell Completions | 289 |
F# Completions | 61 |
C Completions | 819 |
COBOL Completions | 9 |
Julia Completions | 23 |
Rust Completions | 443 |
D Completions | 6 |
Go Completions | 522 |
Total Stars | 4975 |
% of votes with a positive feedback rating | 93% of 5865 |
Total "Very Satisfied" Votes | 5190 |
Total "Somewhat Satisfied" Votes | 577 |
Total "Not Satisfied" Votes | 98 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |