FastPrepToken Expiry with Lazy Deletion
Problems/Token Expiry with Lazy Deletion

Token Expiry with Lazy Deletion

Citadel logoCitadel● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from a Citadel Securities online assessment for an experienced full-time developer, posted in January 2026. The test had three coding tasks. One asked for the number of tokens that are still valid, with expired tokens deleted lazily.

The report names the task only. It gives no methods, expiry rule, examples or limits. Here, every token lasts the same fixed time, and you can generate, renew and count tokens. A token is already expired at its exact expiry time, renewing a token that is unknown or expired does nothing, the times strictly increase, each token id is generated at most once, and each operation should take amortized O(1) time. You get the calls as a list of operations instead of a class. The limits and the examples are ours.

Our version is about 70% the same as the reported question.

A system hands out tokens that each stay valid for timeToLive time units. A token generated or renewed at time t expires at time t + timeToLive. A token is valid at time x only if its expiry time is greater than x, so a token that expires at time x is no longer valid at x.

Process operations in order. There are no tokens at the start. Each operation is one of:

  • [0, tokenId, currentTime]: generate. Create a new token tokenId at currentTime. Nothing is recorded.
  • [1, tokenId, currentTime]: renew. If token tokenId exists and is valid at currentTime, its expiry becomes currentTime + timeToLive. If the token was never generated or has already expired, nothing happens. Nothing is recorded.
  • [2, currentTime]: count. Record the number of tokens that are valid at currentTime.

Return the recorded counts in operation order.

Expired tokens never become valid again, so you can delete them lazily, only when a count reaches them. Each operation should take amortized O(1) time.

Function

countValidTokens(timeToLive: int, operations: int[][]) → int[]

Examples

Example 1

timeToLive = 10operations = [[0,7,1],[0,3,4],[2,5],[1,7,9],[2,12],[2,14],[1,3,16],[2,18],[2,19]]return = [2,2,1,1,0]

Token 7 expires at 11 and token 3 at 14, so the count at time 5 is 2. Renewing token 7 at time 9 moves its expiry to 19, so both tokens are still valid at time 12. Token 3 expires at time 14, so the count at 14 is 1, and the renew of token 3 at time 16 does nothing. Token 7 is still valid at 18 and expires at 19.

Example 2

timeToLive = 3operations = [[1,5,1],[2,2],[0,5,3],[1,5,5],[1,5,7],[2,9],[2,10],[0,6,11],[2,12]]return = [0,1,0,1]

The renew at time 1 does nothing because token 5 does not exist yet, so the count at time 2 is 0. Token 5 is generated at time 3 and renewed at 5 and 7, which moves its expiry to 8 and then 10. It is valid at time 9, so that count is 1. At time 10 token 5 has expired, so the count is 0. Token 6 is generated at time 11, so the count at 12 is 1.

Example 3

timeToLive = 100000000operations = [[0,0,1],[0,100000,2],[2,100000000]]return = [2]

The tokens expire at 100000001 and 100000002, so both are still valid at time 100000000.

Constraints

  • 1 <= timeToLive <= 10^8
  • 1 <= operations.length <= 2 * 10^4
  • Each operation is [0, tokenId, currentTime], [1, tokenId, currentTime] or [2, currentTime].
  • 0 <= tokenId <= 10^5
  • 1 <= currentTime <= 10^8
  • The values of currentTime strictly increase from one operation to the next.
  • Each generate uses a tokenId that was not generated before.

More Citadel Online Assessment questions

  • Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
  • Possible MEX Values After One Optional IncrementOA · Seen Oct 2026
  • Busy IntersectionOA · Seen Sep 2026
  • Shortest Path in an Unweighted GraphOA · Seen Sep 2026
  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Image Processing CostOA · Seen Jul 2026
  • Coprime Pick with Change CostOA · Seen Jul 2026
  • Process SchedulingOA · Seen Mar 2026
  • Employee With the Most OverlapsOA · Seen Feb 2026

Similar questions at other companies

  • Per-Client Sliding-Window Rate LimiterGeneral Motors · OA
  • Per-Domain Request LimiterExpedia · OAExpedia interview questions
  • Truck Position SubscriberOptiver · OAOptiver interview questions
  • Rate Limiter with a Sliding Window per ClientStackAdapt · PHONE SCREENStackAdapt interview questions
  • Per-Client API Rate LimiterDocker · PHONE SCREEN
  • Sliding Window Rate LimiterLotusFlare · ONSITE INTERVIEW
  • Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN
  • Sliding-Window Rate LimiterAmazon · ONSITE INTERVIEW
  • Sliding-Window Rate LimiterUber · PHONE SCREENUber interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
  • Citadel SWE Intern First-Round Questions: 20 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int[] countValidTokens(int timeToLive, int[][] operations) {
      // Write your code here.
    }
}
Checking account…