Authentication System ๐น
Learn this problemProblem statement
Develop a session-based authentication system where each user session generates a new token with a specified time-to-live (TTL) expiration. The TTL expiration is calculated as the current time plus the time-to-live seconds. If a token is renewed, the TTL is extended to the time-to-live seconds after the time of the renewal.
There are three types of queries in this system:
Note: If a token expires at a specific time and any action is performed at that same time, the token's expiration occurs before any other actions are carried out.
Function
getUnexpiredTokens(time_to_live: int, queries: String[][]) โ int[]
Complete the function getUnexpiredTokens in the editor below.
getUnexpiredTokens has the following parameter(s):
- 1.
int time_to_live: the time to live for a token - 2.
String[] queries: the queries
Returns
int[]: the results from type-3 query in the same order it is given
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][1, 0]. At t = 6, the only unexpired token is "aaa". At t = 15, all tokens have expired, so the count of unexpired tokens is 0.Constraints
Unknwon for nowMore Tiktok problems
- Count Access Code PairsOA ยท Seen Jul 2026
- Count Key ChangesOA ยท Seen Jul 2026
- Travel Distance on ScootersOA ยท Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA ยท Seen Jul 2026
- Obstacle Placement QueriesOA ยท Seen Jul 2026
- Repeated Grouped Digit SumOA ยท Seen Jul 2026
- Count Cyclic Digit PairsOA ยท Seen Jun 2026
- Event ID Check Completion TimesOA ยท Seen Jun 2026