Most websites that require user login now utilize a "token" system. Every time a user logs into the website, they are issued a token so that when they go to the website again, they are authenticated with the token so they don't have to log in again. Usually a token has an expiration time so that after certain amount of inactivity, the token is voided.
In this particular system, there are two commands:
Given a list of operations sorted chronologically, determine how many tokens are still active after the final operation.
Parameters
expiry_time: How long since the token was generated or reset before it expires.
operations: An integer matrix with n rows. Each row has 3 entries: operation, token_id, and time, representing an operation.
Result
The number of tokens still valid after the final operation.
Examples
Example 1:
Input
expiry_time = 4
operations = [[0, 1, 1], [0, 2, 2], [1, 1, 5], [1, 2, 7]]
Output: 1
Explanation: Token 1 is initialized at T = 1 and token 2 is initialized at T = 2. When token 1 is reset at T = 5, it is still in the active period, so the token's lifespan is increased to T = 5 + 4 = 9. When token 2 is reset at T = 7, it already expired so nothing happens. After this operation, only token 1 is still valid.
Restrictions