Drawer grids: Peak ticket
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. - Find the largest number in
rowTotals. Store it inlargest. - Complete
drawerGridsPeakTicketso it returnslargest. Return it, do not print it.
Example
If drawers is [[4, 2], [], [3, 1], [5, 3], [3, 1]], then rowTotals is [6, 0, 4, 8, 4] and drawerGridsPeakTicket returns 8.
Rules
- If
rowTotalsis empty, return 0.
Test data
TEST DATA 1: drawers is [[16, 14], [], [16, 14], [0, -2], [5, 3]].
TEST DATA 2: drawers is [[7, 5], [], [7, 5], [-3, -5]].
Examples
Input: drawers = [[16,14],[],[16,14],[0,-2],[5,3]] Output: 30
rowTotals is [30, 0, 30, -2, 8]. The largest number is 30. Return 30.
Input: drawers = [[7,5],[],[7,5],[-3,-5]] Output: 12
rowTotals is [12, 0, 12, -8]. The largest number is 12. Return 12.
Input: drawers = [] Output: 0
rowTotals is []. The list is empty, 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.