Paired drawers: Threshold file
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. - Count the numbers in
mergedthat are at leastk(greater than or equal tok). Store the count inatLeastK. - Complete
pairedDrawersThresholdFileso it returnsatLeastK. Return it, do not print it.
Example
If drawers is [[-9, 3, 8, 8, 8], [-9, 3, 8, 8, 8]] and k is 3, then merged is [-9, -9, 3, 3, 8, 8, 8, 8, 8, 8] and pairedDrawersThresholdFile returns 8.
Rules
- If
mergedis empty, the count is 0. 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 [[-4, 0, 3, 17, 17], []] and k is 7.
TEST DATA 2: drawers is [[-1, 3, 3, 3], [11]] and k is 8.
Examples
Input: drawers = [[-4,0,3,17,17],[]] k = 7 Output: 2
merged is [-4, 0, 3, 17, 17]. Here k is 7. The numbers at least 7 are [17, 17]. There are 2, so return 2.
Input: drawers = [[-1,3,3,3],[11]] k = 8 Output: 1
merged is [-1, 3, 3, 3, 11]. Here k is 8. The numbers at least 8 are [11]. There are 1, so return 1.
Input: drawers = [[],[]] k = 8 Output: 0
merged is []. Here k is 8. The numbers at least 8 are []. There are 0, so return 0.
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.