Authentication System
Learn this problemProblem statement
Implement a session-based authentication system that manages user sessions using unique token IDs and a configurable time-to-live (time_to_live, or TTL) measured in seconds.
When a token is generated, its expiration time is current_time + time_to_live. A token may be renewed only while it is still unexpired; a successful renewal resets its expiration time to current_time + time_to_live.
Process every string in queries in the given order. The system must support these three operations:
generate <token_id> <current_time>: Atcurrent_time, create a new token with the specified ID. Its expiration time iscurrent_time + time_to_live.renew <token_id> <current_time>: Atcurrent_time, extend an existing unexpired token's expiration time tocurrent_time + time_to_live. Ignore the request if the token does not exist or has already expired.count <current_time>: Return the number of unexpired tokens atcurrent_time.
Important: Token expiration is evaluated before processing any action at the same timestamp. If a token's expiration time is exactly equal to current_time, the token is expired and cannot be renewed or counted.
Function
getUnexpiredTokens(time_to_live: int, queries: String[]) → int[]Examples
Example 1
time_to_live = 5queries = ["generate aaa 1","renew aaa 2","count 6","generate bbb 7","renew aaa 8","renew bbb 10","count 15"]return = [1,0]At time 6, token aaa is the only unexpired token, so the first count is 1. At time 15, all tokens have expired, so the second count is 0.
More Microsoft problems
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026
- Maximum Strength of Every NeuronOA · Seen Jul 2026
- Neural Network Subnetwork StrengthOA · Seen Jul 2026
- XOR MultiplicationOA · Seen Jul 2026