Interview Slot Booking
Updated
Problem statement
Build the core of an interview scheduling service. Interviewers mark the hours when they are free, candidates list the open slots for the next 14 days, and candidates book a slot, which is given to a free interviewer automatically.
Time is counted in whole hours, all in the same time zone. A slot is one hour of one interviewer: slot h runs from hour h to hour h + 1. Process the operations in operations in order. For each index i, args[i] holds the arguments of operations[i].
"markSlots"withargs[i] = [interviewerId, startHour, endHour]: the interviewer is free for every slothwithstartHour <= h < endHour. Marking a slot that was already marked changes nothing, even if that slot has been booked. This records nothing."getAvailableSlots"withargs[i] = [now]: record every free slothof every interviewer withnow <= h < now + 336(the next 14 days). List them by increasing hour, and by increasing interviewer ID within the same hour. Record them as one flat row[hour1, interviewerId1, hour2, interviewerId2, ...], which is empty when there are none."bookInterview"withargs[i] = [hour]: a candidate books slothour. Among the interviewers who are free at that hour, the one with the smallest ID gets the interview, so that slot is no longer free. Record[interviewerId]for the chosen interviewer, or[-1]if no interviewer is free at that hour.
Return the recorded rows of all "getAvailableSlots" and "bookInterview" operations, in order.
Function
runInterviewScheduler(operations: String[], args: int[][]) → int[][]Examples
Example 1
operations = ["markSlots","markSlots","getAvailableSlots","bookInterview","getAvailableSlots"]args = [[123,11,14],[456,11,12],[0],[11],[0]]return = [[11,123,11,456,12,123,13,123],[123],[11,456,12,123,13,123]]Interviewer 123 is free for slots 11, 12, and 13. Interviewer 456 is free for slot 11.
The first "getAvailableSlots" lists all four slots: hour 11 with interviewers 123 and 456, then hours 12 and 13 with 123.
The booking for hour 11 goes to 123, the smaller free ID. The second listing no longer has slot 11 of interviewer 123.
Example 2
operations = ["markSlots","bookInterview","bookInterview","markSlots","bookInterview","getAvailableSlots"]args = [[7,100,102],[100],[100],[7,100,101],[101],[100]]return = [[7],[-1],[7],[]]Interviewer 7 is free for slots 100 and 101. The first booking for hour 100 goes to 7. The second booking for hour 100 finds nobody free, so it records [-1].
Marking slot 100 again changes nothing, because that slot was already marked and is now booked. The booking for hour 101 goes to 7. After that, no slot is free, so the listing is empty.
Example 3
operations = ["markSlots","markSlots","getAvailableSlots","getAvailableSlots"]args = [[2,335,337],[1,0,1],[0],[1]]return = [[0,1,335,2],[335,2,336,2]]With now = 0, the window holds hours 0 through 335. It includes slot 0 of interviewer 1 and slot 335 of interviewer 2, but not slot 336.
With now = 1, the window holds hours 1 through 336, so it has slots 335 and 336 of interviewer 2 and no longer has slot 0.
Constraints
1 <= operations.length <= 2000args.length == operations.length- Each
operations[i]is"markSlots","getAvailableSlots", or"bookInterview". - For
"markSlots",args[i] = [interviewerId, startHour, endHour]with1 <= interviewerId <= 1000,0 <= startHour < endHour <= 10^6, andendHour - startHour <= 48. - For
"getAvailableSlots",args[i] = [now]with0 <= now <= 10^6. - For
"bookInterview",args[i] = [hour]with0 <= hour <= 10^6.
More TrueFoundry Phone Screen questions
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Structured Log Stream with QueriesOpenAI · PHONE SCREENOpenAI interview questions
- Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
- Streaming Top-K Frequent ElementsNVIDIA · PHONE SCREENNVIDIA interview questions
- Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
- In-Memory Database with TTL and Historical QueriesZip · PHONE SCREENZip interview questions
- Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
- Banking System with Top ActivityCapital One · ONSITE INTERVIEWCapital One interview questions
- Temporal Key-Field Database with Prefix ScansThe Trade Desk · OA