Drawer grids: Floor 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 smallest number in
rowTotals. Store it insmallest. - Complete
drawerGridsFloorTicketso it returnssmallest. Return it, do not print it.
Example
If drawers is [[-8, -10], [], [10, 8], [5, 3], [5, 3]], then rowTotals is [-18, 0, 18, 8, 8] and drawerGridsFloorTicket returns -18.
Rules
- If
rowTotalsis empty, return 0.
Test data
TEST DATA 1: drawers is [[0, -2], [], [-11, -13], [13, 11], [8, 6]].
TEST DATA 2: drawers is [[9, 7], [], [9, 7], [-1, -3]].
Examples
Input: drawers = [[0,-2],[],[-11,-13],[13,11],[8,6]] Output: -24
rowTotals is [-2, 0, -24, 24, 14]. The smallest number is -24. Return -24.
Input: drawers = [[9,7],[],[9,7],[-1,-3]] Output: -4
rowTotals is [16, 0, 16, -4]. The smallest number is -4. Return -4.
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.