cswork / OA打开练习工作台

其他OA #2

Count Valid Tokens

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)哈希计数模拟/实现迭代器设计

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:

    1. int expiryLimit: the system-defined expiration period
    1. 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