Round desk: Peak ticket
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. - Find the largest number in
finishTimes. Store it inlargest. - Complete
roundDeskPeakTicketso it returnslargest. Return it, do not print it.
Example
If readings is [4, 5, 4, 6, 6] and k is 4, then finishTimes is [4, 21, 12, 23, 25] and roundDeskPeakTicket returns 25.
Rules
- If
finishTimesis empty, return 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 [13, 8, 11, 13, 0] and k is 3.
TEST DATA 2: readings is [8, 9, 9, 9] and k is 1.
Examples
Input: readings = [13,8,11,13,0] k = 3 Output: 45
finishTimes is [44, 29, 40, 45, 0]. The largest number is 45. Return 45.
Input: readings = [8,9,9,9] k = 1 Output: 35
finishTimes is [29, 33, 34, 35]. The largest number is 35. Return 35.
Input: readings = [] k = 6 Output: 0
finishTimes is []. The list is empty, so return 0.
Input limits
- 0 <= input size <= 50000.
- 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.