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 Description
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
Example 1:
Input: time_to_live = 5, queries = [["generate aaa 1"], ["renew aaa 2"], ["count 6"], ["generate bbb 7"], ["renew aaa 8"], ["renew bbb 10"], ["count 15"]]
Output: [1, 0]
Explanation:The output of the system is[1, 0]
. Att = 6
, the only unexpired token is "aaa". Att = 15
, all tokens have expired, so the count of unexpired tokens is 0.
Unknwon for now

input:
output: