This pair of problems evaluates algorithmic problem-solving and data-structure design skills, specifically interval scheduling for minimum room allocation and time-based token lifecycle management, and is commonly asked to measure ability to reason about resource allocation, temporal invariants, and scalability under constraints.
You are given two coding questions.
You are given a list of meetings, where each meeting is an interval [start, end) with integer times (start < end). A single room can host multiple meetings as long as their time intervals do not overlap.
Task: Return the minimum number of rooms required to schedule all meetings.
Input: intervals: List[List[int]] where intervals[i] = [start_i, end_i]
Output: int = minimum number of rooms
Notes/constraints (reasonable interview assumptions):
1 <= len(intervals) <= 2e5
0 <= start_i < end_i <= 1e9
t
do not overlap with intervals that start at time
t
(i.e., treat as
[start, end)
).
Design a token system with a fixed lifetime timeToLive (TTL).
Each token has an expiration time. A token generated at currentTime expires at currentTime + timeToLive.
Implement a class (or module) supporting the following operations:
generate(tokenId: string, currentTime: int) -> void
tokenId
that expires at
currentTime + timeToLive
.
tokenId
already exists, you may assume it is overwritten with the new expiration (state your assumption).
renew(tokenId: string, currentTime: int) -> void
tokenId
exists and is
unexpired
at
currentTime
, update its expiration to
currentTime + timeToLive
.
currentTime
, do nothing.
countUnexpiredTokens(currentTime: int) -> int
currentTime
.
Constraints (reasonable interview assumptions):
2e5
total operations
currentTime
values are non-decreasing across calls
Provide the required outputs with efficient time complexity.