Paired drawers: Total receipt
Stuck or curious how this works? Visualize Two Pointers ↗
Inputs
drawers contains exactly two lists of numbers. The first list is drawers[0]; the second is drawers[1].
Your tasks
- Create a list
merged.drawerscontains two lists, each already sorted from smallest to largest. Combine their numbers into one sortedmerged. Keep all repeated numbers, including copies from both input lists. - Add up every number in
merged. Store the sum intotal. - Complete
pairedDrawersTotalReceiptso it returnstotal. Return it, do not print it.
Example
If drawers is [[-4, 6, 6, 7, 8], [-4, 6, 6, 7, 8]], then merged is [-4, -4, 6, 6, 6, 6, 7, 7, 8, 8] and pairedDrawersTotalReceipt returns 46.
Rules
- If
mergedis empty,totalis 0.
Test data
TEST DATA 1: drawers is [[-8, 0, 14, 14, 16], []].
TEST DATA 2: drawers is [[-6, 6, 6, 6], [18]].
Examples
Input: drawers = [[-8,0,14,14,16],[]] Output: 36
merged is [-8, 0, 14, 14, 16]. Add its numbers to get 36. Return 36.
Input: drawers = [[-6,6,6,6],[18]] Output: 30
merged is [-6, 6, 6, 6, 18]. Add its numbers to get 30. Return 30.
Input: drawers = [[],[]] Output: 0
merged is []. Add its numbers to get 0. Return 0.
Input limits
- 0 <= input size <= 64 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.
- The input has exactly two rows, each containing at most 64 integers.
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 combined length of the two lists. These labels describe how work and memory grow with the input.
Practice focus
Build merged 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.