Drawer grids: Threshold file
Inputs
drawers is a list of rows. Each row is a list of numbers and may be empty.
Your tasks
- Create a list
rowTotals.drawersis a list of rows. Add the numbers in each row. Put one total per row inrowTotals, in row order. An empty row has a total of 0. - Count the numbers in
rowTotalsthat are at leastk(greater than or equal tok). Store the count inatLeastK. - Complete
drawerGridsThresholdFileso it returnsatLeastK. Return it, do not print it.
Example
If drawers is [[4, 2], [], [6, 4], [10, 8], [-7, -9]] and k is 3, then rowTotals is [6, 0, 10, 18, -16] and drawerGridsThresholdFile returns 3.
Rules
- If
rowTotalsis empty, the count is 0. k(a whole number from 1 to 8) is the threshold in task 2: compare each number with it.
Test data
TEST DATA 1: drawers is [[-12, -14], [], [0, -2], [8, 6], [8, 6]] and k is 3.
TEST DATA 2: drawers is [[4, 2], [], [4, 2], [4, 2]] and k is 3.
Examples
Input: drawers = [[-12,-14],[],[0,-2],[8,6],[8,6]] k = 3 Output: 2
rowTotals is [-26, 0, -2, 14, 14]. Here k is 3. The numbers at least 3 are [14, 14]. There are 2, so return 2.
Input: drawers = [[4,2],[],[4,2],[4,2]] k = 3 Output: 3
rowTotals is [6, 0, 6, 6]. Here k is 3. The numbers at least 3 are [6, 6, 6]. There are 3, so return 3.
Input: drawers = [] k = 2 Output: 0
rowTotals is []. Here k is 2. The numbers at least 2 are []. There are 0, so return 0.
Input limits
- 0 <= input size <= 16 per row.
- 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 have no decimal part. They range from -1,000,000 to 1,000,000. Follow any extra input rules in task 1.
Efficiency goal
Big-O describes how the work or memory needed grows as the input gets larger.
Efficiency goal: time O(n); extra memory, including the helper list, O(n). n is the input length. These labels describe how work and memory grow with the input.
Practice focus
Build rowTotals 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.