FastPrepDynamic Batch Decode Trace
Problems/Dynamic Batch Decode Trace

Dynamic Batch Decode Trace

xAI logoxAI● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report asks for an inference-style decoder that keeps a batch full while requests finish at different times, stops at a token or a maximum length, and keeps the slot-to-request mapping. Our version replaces the outside model and callbacks with scripted next tokens and a trace for each slot. It uses one stop token and counts every consumed token toward maxTokens.

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.

  1. Create batchSize numbered slots and initially fill the lowest slots with the earliest requests.
  2. Each model round consumes one next token for every occupied slot, in ascending slot order. Add r:token to that round's trace.
  3. A request completes after consuming stopToken or its maxTokens-th token.
  4. 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 maxTokens entries or contains at least maxTokens entries.
  • 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

xAI interview experiences

  • xAI New Grad AI Coding Interview and Take-Home: 3 Experiences
All xAI interview questionsSee xAI hiring insights
Saved
class Solution {
    public String[][] dynamicBatchTrace(
            String[][] scriptedTokens, int batchSize, int maxTokens, String stopToken) {
        // Write your code here.
    }
}
Checking account…