Booking rack: Threshold file
Inputs
drawers is a list of bookings. Each row is [start, end].
Your tasks
- Create a list
acceptedLengths. Each booking is [start, end]. It uses time from start up to, but not including, end. Sort bookings by end time, from earliest to latest. For matching end times, put the earlier start first. Accept the first booking. Then accept a booking only if it starts at or after the end of the last one accepted. Record the length, end - start, of each accepted booking. Keep acceptance order. Negative times are allowed. With no bookings,acceptedLengthsis empty. - Count the numbers in
acceptedLengthsthat are at leastk(greater than or equal tok). Store the count inatLeastK. - Complete
bookingRackThresholdFileso it returnsatLeastK. Return it, do not print it.
Example
If drawers is [[4, 9], [5, 10], [0, 3], [10, 11], [8, 13]] and k is 6, then acceptedLengths is [3, 5, 1] and bookingRackThresholdFile returns 0.
Rules
- If
acceptedLengthsis 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 [[17, 21], [19, 24], [19, 23], [-9, -3], [4, 5]] and k is 8.
TEST DATA 2: drawers is [[3, 7], [4, 8], [5, 9], [-5, -3]] and k is 4.
Examples
Input: drawers = [[17,21],[19,24],[19,23],[-9,-3],[4,5]] k = 8 Output: 0
acceptedLengths is [6, 1, 4]. Here k is 8. The numbers at least 8 are []. There are 0, so return 0.
Input: drawers = [[3,7],[4,8],[5,9],[-5,-3]] k = 4 Output: 1
acceptedLengths is [2, 4]. Here k is 4. The numbers at least 4 are [4]. There are 1, so return 1.
Input: drawers = [] k = 5 Output: 0
acceptedLengths is []. Here k is 5. The numbers at least 5 are []. There are 0, so return 0.
Input limits
- 0 <= input size <= 64.
- 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.
Efficiency goal
Big-O describes how the work or memory needed grows as the input gets larger.
Efficiency goal: time O(n log n); extra memory, including the helper list, O(n). n is the input length. These labels describe how work and memory grow with the input.
Practice focus
Build acceptedLengths 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.