Drawer grids: Even-key census
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 even numbers in
rowTotals. Store the count inevenCount. A number is even when it divides by 2 with no remainder. - Complete
drawerGridsEvenKeyCensusso it returnsevenCount. Return it, do not print it.
Example
If drawers is [[8, 6], [], [6, 4], [-6, -8], [8, 6]], then rowTotals is [14, 0, 10, -14, 14] and drawerGridsEvenKeyCensus returns 5.
Rules
- 0 and negative even numbers count too.
- If
rowTotalsis empty, return 0.
Test data
TEST DATA 1: drawers is [[0, -2], [], [17, 15], [4, 2], [-8, -10]].
TEST DATA 2: drawers is [[4, 2], [], [4, 2], [-7, -9]].
Examples
Input: drawers = [[0,-2],[],[17,15],[4,2],[-8,-10]] Output: 5
rowTotals is [-2, 0, 32, 6, -18]. The even numbers are [-2, 0, 32, 6, -18]. There are 5, so return 5.
Input: drawers = [[4,2],[],[4,2],[-7,-9]] Output: 4
rowTotals is [6, 0, 6, -16]. The even numbers are [6, 0, 6, -16]. There are 4, so return 4.
Input: drawers = [] Output: 0
rowTotals is []. The even numbers are []. There are 0, so return 0.
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.