Shared drawers: Threshold file
Stuck or curious how this works? Visualize Sorting ↗
Inputs
drawers contains exactly two lists of numbers. The first list is drawers[0]; the second is drawers[1].
Your tasks
- Create a list
shared.drawerscontains two lists of numbers. Find the numbers that appear in both lists. Put each matching number insharedonly once. Sortsharedfrom smallest to largest. - Count the numbers in
sharedthat are at leastk(greater than or equal tok). Store the count inatLeastK. - Complete
sharedDrawersThresholdFileso it returnsatLeastK. Return it, do not print it.
Example
If drawers is [[8, -7, 5, 5, 11], [8, -7, 5, 5, 11]] and k is 5, then shared is [-7, 5, 8, 11] and sharedDrawersThresholdFile returns 3.
Rules
- If
sharedis 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 [[0, -6, 12, 18, 12], []] and k is 5.
TEST DATA 2: drawers is [[6, 6, -8, 6], [14]] and k is 3.
Examples
Input: drawers = [[0,-6,12,18,12],[]] k = 5 Output: 0
shared is []. Here k is 5. The numbers at least 5 are []. There are 0, so return 0.
Input: drawers = [[6,6,-8,6],[14]] k = 3 Output: 0
shared is []. Here k is 3. The numbers at least 3 are []. There are 0, so return 0.
Input: drawers = [[],[]] k = 4 Output: 0
shared is []. Here k is 4. The numbers at least 4 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 + d log d); extra memory, including the helper list, O(n). n is the combined length of the two lists; d is the number of different values. These labels describe how work and memory grow with the input.
Practice focus
Build shared 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.