Skip to content

Practice Design Authentication Manager

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1797
LeetCode Problem

Design Authentication Manager

Problem Statement

AuthenticationManager(timeToLive) tracks token expiry. generate(tokenId,currentTime) creates a token expiring at currentTime + timeToLive. renew extends an existing unexpired token from the renewal time; absent or expired tokens are ignored. countUnexpiredTokens returns the number still valid. Expiration happens before other actions at the same time. Practice approach: Store token-to-expiry mappings and compare expiry strictly greater than the current time. A scan suffices for 2000 calls; a time-ordered structure can expire older entries efficiently. Do not renew a token at its expiry instant. Test exact expiry and absent-token renewal.

Source: Design Authentication Manager on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["AuthenticationManager","generate","countUnexpiredTokens","renew","countUnexpiredTokens"]
[[3],["a",1],[3],["a",4],[5]]
Output
[null,null,1,null,0]
Explanation

Token a expires at time 4. Its renewal at exactly 4 is ignored.

Constraints

1 <= timeToLive, currentTime <= 10^8
Token IDs contain 1 to 5 lowercase letters.
Generated token IDs are unique.
Current times strictly increase across calls.
At most 2000 total calls.

Related LeetCode Problems

Practice more problems similar to Design Authentication Manager.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.