Insertion tabs: Floor ticket
Stuck or curious how this works? Visualize Binary Search ↗
Inputs
drawers contains exactly two lists: the sorted numbers in drawers[0], then the query numbers in drawers[1].
Your tasks
- Create a list
positions.drawerscontains two rows: a sorted number list, then a list of queries. Each query is a number to look up. For each query, find the first position in the sorted list whose number is at least the query. Positions, also called indexes, start at 0. If no number is large enough, record the length of the sorted list. Put the answers in query order. - Find the smallest number in
positions. Store it insmallest. - Complete
insertionTabsFloorTicketso it returnssmallest. Return it, do not print it.
Example
If drawers is [[-8, 3, 3, 9, 9], [3, 3, -8, 9, 9]], then positions is [1, 1, 0, 3, 3] and insertionTabsFloorTicket returns 0.
Rules
- If
positionsis empty, return 0.
Test data
TEST DATA 1: drawers is [[-3, 0, 7, 10, 10], []].
TEST DATA 2: drawers is [[-8, 2, 2, 2], [7]].
Examples
Input: drawers = [[-3,0,7,10,10],[]] Output: 0
positions is []. The list is empty, so return 0.
Input: drawers = [[-8,2,2,2],[7]] Output: 4
positions is [4]. The smallest number is 4. Return 4.
Input: drawers = [[],[]] Output: 0
positions is []. The list is empty, so 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(q log(n+1)); extra memory, including the helper list, O(n). n is the length of the sorted number list; q is the number of queries. These labels describe how work and memory grow with the input.
Practice focus
Build positions 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.