其他OA #2
Count Valid Tokens
估计中等评测数据准备中,可先阅读题面
The other question asked in the same batch is LC647.
After a user logs in, they receive a token. If the token exceeds the system-defined expiration period (expiryLimit), it becomes invalid. However, if the token is reset within the period, the expiration time is extended.
Valid tokens can be reset repeatedly.
Expired or non-existent tokens will have their reset operations ignored.
Expired tokens cannot be used again.
Command format: [type, token_id, T]
type 0 (create): Create a token with an expiration time set to T + expiryLimit.
type 1 (reset): Extend the token's expiration time to T + expiryLimit.
Initially, there are no tokens. Process the requests in order and determine how many tokens are still valid at the maximum time point.
Function Description
Complete the function countValidTokens in the editor.
countValidTokens has the following parameters:
-
int expiryLimit: the system-defined expiration period
-
int[][] commands: a 2D array of commands where each command is of the format [type, token_id, T] Returns int: the number of valid tokens at the maximum time point