You are running a car dealership and currently have 2 employees.
We are going to be building a basic function to deal with customers booking appointments with your employees.
You have the following constraints:
- An appointment is represented by a pair of integers [start time, duration]
- Customers get assigned to either of your employees and they don’t get to choose who they get
- Your 2 employees can only handle one customer at a time
Implement a DealershipScheduler class with the following method:
bool book(int startTime, int duration)
Return true if you can book an appointment for these times, and false if it would result in your employees being double-booked.
Sample bookings:
[10, 10], [50, 10], [10, 30], [5, 10], [5, 5], [25, 30]
This problem is a two-server interval scheduling task.
Each booking request is an interval [start, end) and you must decide if it can fit into either of the two employees’ schedules without overlap.
Core idea:
- Maintain two sets of existing intervals (employee A & B).
- For each new request, try putting it into employee A (no overlap).
- If not possible, try employee B.
- If both overlap → return false.
- Otherwise insert and return true.
Essentially, you’re checking if at most 2 overlapping intervals exist at any time.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Tiktok, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Tiktok or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.