def count_valid_tokens(expiry_limit: int, commands: list[list[int]]) -> int:
Authentication tokens. After a user logs in they receive a token. The token expires once the system's time limit, expiryLimit, has passed; resetting it while it is still valid (up to and including its expiry time, as the example shows) extends it. A valid token can be reset any number of times. A reset of a token that has expired or does not exist is ignored, and an expired token cannot be used again.
Each command is [type, token_id, T]:
type 0 (create): create token token_id; it expires at T + expiryLimit.type 1 (reset): extend token token_id so it expires at T + expiryLimit.There are no tokens at the start. Process the commands in order, then return how many tokens are still valid at the latest time T.
expiryLimit = 4
commands = [[0, 1, 1], [0, 2, 2], [1, 1, 5], [1, 2, 7]]
[0, 1, 1] create token 1 at T = 1; it expires at 1 + 4 = 5
[0, 2, 2] create token 2 at T = 2; it expires at 2 + 4 = 6
[1, 1, 5] reset token 1 at T = 5; still valid (T <= 5), so it now expires at 5 + 4 = 9
[1, 2, 7] reset token 2 at T = 7; it expired at T = 6, so the reset is ignored
At T = 7 only token 1 is still valid. Return 1.
Reported three times in Citadel online assessments: in February 2025 as the second of two problems, with the prompt and example above; in early 2026 on HackerRank for an EQR role, alongside a palindrome problem and a longest-path-in-a-tree problem, where the candidate called it a lazy delete and solved all three in half an hour; and in mid-2026, again for EQR, described as a bit simpler than LeetCode 1797 and described as using a hash map and a pass over the list.
Only the February 2025 report gives the prompt; the other two confirm the problem and the approach.
Authentication tokens. After a user logs in they receive a token. The token expires once the system's time limit, expiryLimit, has passed; resetting it while it is still valid (up to and including its expiry time, as the example shows) extends it. A valid token can be reset any number of times. A reset of a token that has expired or does not exist is ignored, and an expired token cannot be used again.
Each command is [type, token_id, T]:
type 0 (create): create token token_id; it expires at T + expiryLimit.type 1 (reset): extend token token_id so it expires at T + expiryLimit.There are no tokens at the start. Process the commands in order, then return how many tokens are still valid at the latest time T.
expiryLimit = 4
commands = [[0, 1, 1], [0, 2, 2], [1, 1, 5], [1, 2, 7]]
[0, 1, 1] create token 1 at T = 1; it expires at 1 + 4 = 5
[0, 2, 2] create token 2 at T = 2; it expires at 2 + 4 = 6
[1, 1, 5] reset token 1 at T = 5; still valid (T <= 5), so it now expires at 5 + 4 = 9
[1, 2, 7] reset token 2 at T = 7; it expired at T = 6, so the reset is ignored
At T = 7 only token 1 is still valid. Return 1.
What passers do: Lazy deletion: the candidate who described it that way solved all three problems of the assessment in half an hour
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 62 Citadel questions, refreshed monthly from new candidate reports.