← 返回 uber 的题目列表Schedule Meeting / Meeting Scheduler (interval scheduling with updates and deletions)
类型:online_judge
Problem: Schedule Meeting (interval scheduling with updates and deletions)
You are given a set of existing meetings (unordered). Each meeting is a half-open interval [start, end) where start < end.
Implement a calendar module supporting:
schedule(start, end): Try to add a new meeting [start, end).
If it overlaps any existing meeting, return false (do not add it).
Otherwise, add it and return true.
purge(t): Given a fixed time t, delete all meetings whose end time <= t. After deletion, they should not participate in future conflict checks.
Task
Design and implement the two operations.
Discuss what data structure can optimize the runtime (e.g., an ordered map / balanced BST).
Constraints
Number of operations Q up to 2 * 10^5
0 <= start, end, t <= 10^9
Edge cases to cover
Empty calendar insert and purge
Touching endpoints: e.g. [10,20) and [20,30) are not overlapping
Correct behavior after purging and re-inserting
Example I/O format
First line: integer Q
Next Q lines:
S start end for schedule
P t for purge
Print true/false for each S operation.
(See sample testcases in the Chinese section.)
Example
Input
6
S 10 20
S 15 18
S 20 25
P 20
S 5 10
S 9 12
Output
true
false
true
true
false