Shared drawers: Peak ticket
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. - Find the largest number in
shared. Store it inlargest. - Complete
sharedDrawersPeakTicketso it returnslargest. Return it, do not print it.
Example
If drawers is [[8, -9, 1, 10, 8], [8, -9, 1, 10, 8]], then shared is [-9, 1, 8, 10] and sharedDrawersPeakTicket returns 10.
Rules
- If
sharedis empty, return 0. - If every number is negative, return the largest negative number. Do not replace it with 0.
Test data
TEST DATA 1: drawers is [[-12, 10, 17, 17, 0], []].
TEST DATA 2: drawers is [[3, 3, -5, 3], [14]].
Examples
Input: drawers = [[-12,10,17,17,0],[]] Output: 0
shared is []. The list is empty, so return 0.
Input: drawers = [[3,3,-5,3],[14]] Output: 0
shared is []. The list is empty, so return 0.
Input: drawers = [[],[]] Output: 0
shared is []. The list is empty, so return 0.
Input limits
- 0 <= input size <= 50000 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 50000 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.