Round desk: Total receipt
Stuck or curious how this works? Visualize Stack Operations ↗
Inputs
readings is a list of integers (numbers with no decimal part). It may be empty, and numbers may repeat unless task 1 says otherwise.
Your tasks
- Create a list
finishTimes. Each number inreadingsis the work time needed by a job. All jobs are ready at time 0, in input order. The worker gives the first job up toktime units. If it still needs work, put it at the back of the line. Then serve the next job. Record when each job finishes, measured from time 0. Record these finish times in original job order. A job needing 0 time finishes at time 0 and uses no worker time. - Add up every number in
finishTimes. Store the sum intotal. - Complete
roundDeskTotalReceiptso it returnstotal. Return it, do not print it.
Example
If readings is [7, 12, 0, 1, 7] and k is 1, then finishTimes is [20, 27, 0, 3, 22] and roundDeskTotalReceipt returns 72.
Rules
- If
finishTimesis empty,totalis 0. k(a whole number from 1 to 8) is the most time units a job gets in one turn.
Test data
TEST DATA 1: readings is [9, 16, 16, 0, 9] and k is 4.
TEST DATA 2: readings is [2, 3, 2, 2] and k is 5.
Examples
Input: readings = [9,16,16,0,9] k = 4 Output: 171
finishTimes is [33, 46, 50, 0, 42]. Add its numbers to get 171. Return 171.
Input: readings = [2,3,2,2] k = 5 Output: 23
finishTimes is [2, 5, 7, 9]. Add its numbers to get 23. Return 23.
Input: readings = [] k = 1 Output: 0
finishTimes is []. Add its numbers to get 0. Return 0.
Input limits
- 0 <= input size <= 64.
- k is a whole number from 1 to 8. Answers fit in a signed 32-bit integer: -2,147,483,648 through 2,147,483,647.
- Input numbers are whole numbers from 0 through 20.
Efficiency goal
Big-O describes how the work or memory needed grows as the input gets larger.
Efficiency goal: time O(n + total/k); extra memory, including the helper list, O(n). n is the input length; total is all job work time added together. These labels describe how work and memory grow with the input.
Practice focus
Build finishTimes first, then return exactly what the tasks ask for. Follow the order, keep repeated values when the rule says so, and check the empty case.