This is one of the question which was appeared in Assesment. As I was not able to correctly solve it can someone provide answer / solution / intuition to this question?
Note: Question is how I remember it, there may be some inconsistencies.
Given time_to_live parameter of tokens.
and given Q queries of 3 types-
- generate token currentTime - generate token named 'token' at time 'currentTime'
- renew token currentTime - renew token named 'token' to => currentTime + time_to_live
- count currentTime - count of the number of tokens not expired at time 'currentTime'.
Assume, generate always has unique tokenids, renew has tokenids which are generated, if expiry time of token is T it is not alive at time T.
return the result of count queries.
input format -
time_to_live
Q
generate
.
.
renew
.
.
count
.
.
The order of these 3 types of queries is changing.
Sample -
5
7
generate T1 0
generate T2 1
renew T1 3
count 3
renew T2 4
count 7
count 8o/p = [2, 1, 0]
constraints -
1 < time_to_live < 1e8
1 < Q < 1e5
0 <= currentTime <= 1e8
1 <= Token length <= 5
Comments (1)


