Events have (operation, room_id, user_id, timestamp), where operation is create, join, or leave. Creating a room also places that user inside it.
Question
Events have `(operation, room_id, user_id, timestamp)`, where `operation` is `create`, `join`, or `leave`. Creating a room also places that user inside it.
Implement a batch function that returns total person-seconds per room and a live tracker that ranks rooms by current participant count:
```python
def calculate_active_time(events: list, current_time: int | None = None) -> dict[str, int]: ...
class LiveRoomTracker:
def process_event(self, operation, room_id, user_id, timestamp) -> None: ...
def get_top_k(self, k: int) -> list[tuple[str, int]]: ...
```
For batch processing, sort by timestamp and ignore exact duplicate events. A user may occupy only one room: joining another closes the previous stay at that timestamp. Rejoining the same room is a no-op, and an unmatched leave is ignored. Open stays count through `current_time` when supplied; otherwise they contribute nothing. Live top-k breaks count ties by room ID.
Equal-time events retain input order after deduplication. Zero-duration room totals are omitted. When supplied, `current_time` is at least the latest event timestamp. Inputs use integer timestamps and string IDs. Live operations use arrival order; `get_top_k` returns tuples and returns `[]` when `k<=0`. The constructor takes no arguments. `TwitterSpacesTracker` is a compatibility alias for older callers, not a second implementation requirement. The supplied `run_case` is fixture dispatch glue.
## Design discussion (not graded)
1. Rank rooms over only the most recent time window.
2. Compare bucketed counters, heaps, and ordered frequency buckets.
3. Distribute processing while preserving one user's event order.
4. Handle late, duplicate, and corrected events with event-time watermarks.The public brief is identical for people and crawlers. Account access changes tools, not the indexed description.