Dynamic Batch Decode Trace
Updated
Problem statement
There are requests 0..scriptedTokens.length-1 waiting in order. For request r, scriptedTokens[r] lists the successive next tokens returned by the simulated model.
- Create
batchSizenumbered slots and initially fill the lowest slots with the earliest requests. - Each model round consumes one next token for every occupied slot, in ascending slot order. Add
r:tokento that round's trace. - A request completes after consuming
stopTokenor itsmaxTokens-th token. - Only after the entire round completes, free completed slots and refill the lowest free slots with waiting requests in increasing request-ID order.
Return one trace row per model round. A final round may contain fewer than batchSize entries.
Function
dynamicBatchTrace(scriptedTokens: String[][], batchSize: int, maxTokens: int, stopToken: String) → String[][]Examples
Example 1
scriptedTokens = [["a","b","<STOP>"],["x","<STOP>"],["m","n","o","p"],["q","<STOP>"]]batchSize = 2maxTokens = 3stopToken = "<STOP>"return = [["0:a","1:x"],["0:b","1:<STOP>"],["0:<STOP>","2:m"],["3:q","2:n"],["3:<STOP>","2:o"]]Request 1 frees slot 1 after round 2, so request 2 enters there. Request 0 then frees slot 0, which request 3 takes. Request 2 finishes by reaching three consumed tokens.
Example 2
scriptedTokens = [["a","b"],["x","y"]]batchSize = 4maxTokens = 2stopToken = "!"return = [["0:a","1:x"],["0:b","1:y"]]The batch is never full because only two requests exist. Both finish together at maxTokens = 2.
Constraints
1 <= scriptedTokens.length <= 100000.1 <= batchSize <= 1000.1 <= maxTokens <= 1000.- Each request contains a stop token within its first
maxTokensentries or contains at leastmaxTokensentries. - Tokens are non-empty ASCII strings and contain no
:. - The total number of consumed tokens is at most
1000000.
More xAI interview questions
- Live Top-K Spaces by Active UsersONSITE INTERVIEW · Seen Jan 2026
- Total Active Time by SpaceONSITE INTERVIEW · Seen Jan 2026
- Nested Transaction Key-Value StoreONSITE INTERVIEW · Seen Oct 2025
- Weighted LRU CacheONSITE INTERVIEW · Seen Oct 2025
- LFU CacheONSITE INTERVIEW · Seen Sep 2025
- Cached Lazy Token BucketsONSITE INTERVIEW · Seen Sep 2025
- Least Recently Used CacheONSITE INTERVIEW · Seen Jun 2025
- Resumable List IteratorPHONE SCREEN · Seen Apr 2026
- Earliest Dataset Readiness in a PipelinePHONE SCREEN · Seen Mar 2026
- Largest Plus SignOA · Seen May 2025
Similar questions at other companies
- Durable Work Queue OperationsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Keyed Bounded Executor ScheduleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Ad Score Scheduler With DelayGoogle · ONSITE INTERVIEWGoogle interview questions
- Named Async Task SchedulerAirwallex · OAAirwallex interview questions
- Price-Time Order MatchingTwo Sigma · PHONE SCREENTwo Sigma interview questions
- Batch API Requests with Retry DelaysDecagon · PHONE SCREENDecagon interview questions
- Combine the Two Smallest Until All Reach kAdobe · PHONE SCREENAdobe interview questions
- Limit Order MatchingHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Scheduled Payments with Account AliasesCoinbase · ONSITE INTERVIEWCoinbase interview questions