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]
✅ English Summary (Short & Clear)
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.
这是一个 双员工预约调度问题 。
每个预约是一个时间区间 [start, end),你的任务是判断:
能否把新预约安排给任意一个员工,且不与该员工已有预约冲突。
核心思路:
- 用两个数组分别存员工 A、员工 B 的已预约时间。
- 对新预约,先尝试放进 A:不重叠就放进去。
- 若冲突,再试 B。
- 若两个都冲突 → 返回
false。 - 成功放入任一员工 → 返回
true。
本质是检查是否会出现 同时超过 2 个预约重叠。
VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Tiktok、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Tiktok 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。