Paired drawers: First qualifying slip
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. - Read
mergedfrom left to right. Find the first number that is at leastkand store that number, not its position, infirstMatch. - Complete
pairedDrawersFirstQualifyingSlipso it returnsfirstMatch. Return it, do not print it.
Example
If drawers is [[-3, 3, 4, 4, 4], [-3, 3, 4, 4, 4]] and k is 6, then merged is [-3, -3, 3, 3, 4, 4, 4, 4, 4, 4] and pairedDrawersFirstQualifyingSlip returns -1.
Rules
- If no number is at least
k, return -1. k(a whole number from 1 to 8) is the threshold in task 2: compare each number with it.
Test data
TEST DATA 1: drawers is [[-3, 0, 10, 15, 15], []] and k is 3.
TEST DATA 2: drawers is [[-5, 7, 7, 7], [17]] and k is 1.
Examples
Input: drawers = [[-3,0,10,15,15],[]] k = 3 Output: 10
merged is [-3, 0, 10, 15, 15]. Here k is 3. The first number at least 3 is 10. Return that value.
Input: drawers = [[-5,7,7,7],[17]] k = 1 Output: 7
merged is [-5, 7, 7, 7, 17]. Here k is 1. The first number at least 1 is 7. Return that value.
Input: drawers = [[],[]] k = 2 Output: -1
merged is []. Here k is 2. No number is at least 2, so return -1.
Input limits
- 0 <= input size <= 64 per row.
- k is a whole number from 1 to 8. 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.