Leetcode Problem 1797. Design Authentication Manager

1797. Design Authentication Manager

Leetcode Solutions

HashMap with Expiry Time Management

  1. Initialize a HashMap to store token IDs and their expiry times.
  2. When generating a token, add the token ID to the HashMap with the current time plus timeToLive as its value.
  3. When renewing a token, check if the token exists and if it has not expired. If valid, update its expiry time in the HashMap.
  4. When counting unexpired tokens, iterate through the HashMap and count the number of tokens whose expiry time is greater than the current time.
UML Thumbnail

Priority Queue with Lazy Expiry Check

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...