Drawer grids: Positive proof strip
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. - Create a list
positiveValuesthat keeps only the numbers inrowTotalsthat are greater than 0, in the same order. - Complete
drawerGridsPositiveProofStripso it returnspositiveValues. Return it, do not print it.
Example
If drawers is [[3, 1], [], [9, 7], [-3, -5], [3, 1]], then rowTotals is [4, 0, 16, -8, 4] and drawerGridsPositiveProofStrip returns [4, 16, 4].
Rules
- Keep repeated numbers.
- If no number is greater than 0, return [].
Test data
TEST DATA 1: drawers is [[-10, -12], [], [20, 18], [20, 18], [0, -2]].
TEST DATA 2: drawers is [[5, 3], [], [5, 3], [5, 3]].
Examples
Input: drawers = [[-10,-12],[],[20,18],[20,18],[0,-2]] Output: [38,38]
rowTotals is [-22, 0, 38, 38, -2]. Keep only numbers greater than 0, without changing their order. Return [38, 38].
Input: drawers = [[5,3],[],[5,3],[5,3]] Output: [8,8,8]
rowTotals is [8, 0, 8, 8]. Keep only numbers greater than 0, without changing their order. Return [8, 8, 8].
Input: drawers = [] Output: []
rowTotals is []. Keep only numbers greater than 0, without changing their order. Return [].
Input limits
- 0 <= input size <= 16 per row.
- 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.