Process Calendar Events with Deletion, Pagination, and Overlap Queries
Company: Lead
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
# Process Calendar Events with Deletion, Pagination, and Overlap Queries
Process operations against an in-memory calendar. Every event has a unique name, an integer start time, and an integer end time. Event intervals are half-open: `[start, end)`.
```python
def process_calendar(operations: list[list[str]]) -> list[list[str]]:
...
```
Operations have these forms:
- `["INSERT", name, start, end]`: add an event. The input guarantees that `name` is not already present and `int(start) < int(end)`.
- `["DELETE", name]`: remove the named event if it exists; otherwise do nothing.
- `["EVENTS"]`: output all current event names sorted by `(start, end, name)`.
- `["PAGE", page_size, page_num]`: output one zero-based page from that same sorted order. Return an empty list when the page starts beyond the end.
- `["OVERLAP", query_start, query_end]`: output the names of all events that intersect `[query_start, query_end)`, again sorted by `(start, end, name)`. The query interval is valid and non-empty.
Arguments other than names are decimal integer strings. Return one list of names for each `EVENTS`, `PAGE`, or `OVERLAP` operation, in encounter order.
## Constraints
- `0 <= len(operations) <= 200_000`
- Times fit in signed 64-bit integers.
- `1 <= page_size <= 10_000` and `page_num >= 0`.
- Event names are non-empty ASCII strings.
## Example
```text
Input:
operations = [
["INSERT", "review", "30", "50"],
["INSERT", "standup", "10", "20"],
["INSERT", "planning", "18", "35"],
["EVENTS"],
["PAGE", "2", "1"],
["OVERLAP", "19", "31"],
["DELETE", "planning"],
["EVENTS"]
]
Output:
[
["standup", "planning", "review"],
["review"],
["standup", "planning", "review"],
["standup", "review"]
]
```
Quick Answer: Practice implementing an in-memory calendar that supports inserts, deletions, stable ordering, zero-based pagination, and half-open interval overlap queries. The prompt tests careful operation parsing, deterministic tie-breaking, boundary semantics, and performance across a large command stream.