Round desk: Threshold file
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. - Count the numbers in
finishTimesthat are at leastk(greater than or equal tok). Store the count inatLeastK. - Complete
roundDeskThresholdFileso it returnsatLeastK. Return it, do not print it.
Example
If readings is [2, 5, 5, 5, 12] and k is 6, then finishTimes is [2, 7, 12, 17, 29] and roundDeskThresholdFile returns 4.
Rules
- If
finishTimesis empty, the count is 0. k(a whole number from 1 to 8) is the most time units a job gets in one turn, and also the threshold in task 2.
Test data
TEST DATA 1: readings is [13, 10, 0, 10, 9] and k is 5.
TEST DATA 2: readings is [6, 9, 6, 6] and k is 4.
Examples
Input: readings = [13,10,0,10,9] k = 5 Output: 4
finishTimes is [42, 30, 0, 35, 39]. Here k is 5. The numbers at least 5 are [42, 30, 35, 39]. There are 4, so return 4.
Input: readings = [6,9,6,6] k = 4 Output: 4
finishTimes is [18, 27, 24, 26]. Here k is 4. The numbers at least 4 are [18, 27, 24, 26]. There are 4, so return 4.
Input: readings = [] k = 1 Output: 0
finishTimes is []. Here k is 1. The numbers at least 1 are []. There are 0, so 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.