Drawer grids: Total receipt
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. - Add up every number in
rowTotals. Store the sum intotal. - Complete
drawerGridsTotalReceiptso it returnstotal. Return it, do not print it.
Example
If drawers is [[2, 0], [], [12, 10], [5, 3], [-6, -8]], then rowTotals is [2, 0, 22, 8, -14] and drawerGridsTotalReceipt returns 18.
Rules
- If
rowTotalsis empty,totalis 0.
Test data
TEST DATA 1: drawers is [[-7, -9], [], [16, 14], [6, 4], [6, 4]].
TEST DATA 2: drawers is [[8, 6], [], [-8, -10], [8, 6]].
Examples
Input: drawers = [[-7,-9],[],[16,14],[6,4],[6,4]] Output: 34
rowTotals is [-16, 0, 30, 10, 10]. Add its numbers to get 34. Return 34.
Input: drawers = [[8,6],[],[-8,-10],[8,6]] Output: 10
rowTotals is [14, 0, -18, 14]. Add its numbers to get 10. Return 10.
Input: drawers = [] Output: 0
rowTotals is []. Add its numbers to get 0. 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.