FastPrepPaged KV Cache Access
Problems/Paged KV Cache Access

Paged KV Cache Access

NVIDIA logoNVIDIA● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a phone screen for an NVIDIA software engineering internship. The candidate was given a C++ code framework and implemented the access path of a KV cache stored in fixed-size pages, then walked through the code by hand.

The report shows no code, no interface and no input or output format, so we chose every rule that changes an answer: a pool of numbered pages of a fixed size, one page table per named sequence, and one integer per token in place of its key and value vectors; a position is found as a page-table entry and an offset, and LOOKUP returns the physical page; a page is taken only when a token needs one; a new page is always the lowest-numbered free page; an append that needs more pages than are free stores nothing and returns [-1]; FREE gives back all of a sequence's pages, forgets the sequence and returns [0] for an unknown name; READ and LOOKUP always stay inside a stored sequence; the operation strings, the limits and all the examples are ours too. The original framework, the GPU details and the follow-up discussion are not part of this problem.

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

Implement the access path of a paged key/value (KV) cache: process operations in order and return one list of integers per operation.

The cache has numPages physical pages, numbered 0 to numPages - 1, and each page holds pageSize tokens. Each sequence has a name and a page table: the list of the physical pages it uses, in order. The tokens of a sequence have positions 0, 1, 2, ... in the order they were appended. Position p is stored in the page at entry p / pageSize of the page table (integer division), at offset p % pageSize in that page. Each token is a single integer that stands in for its key and value vectors.

Each operation is a string, and its result is a list of integers:

  • "APPEND|name|v1,v2,...,vk" adds the values as new tokens at the end of sequence name. A name that is not stored starts a new, empty sequence. A token takes a new page only when the sequence has no page yet or its last page is full. The result is the page numbers this append took, in the order it took them; [] if all the values fit in the free room of the last page; or [-1] if the append is refused (see the two page rules below).
  • "READ|name|start|count" returns the values at positions start to start + count - 1 of name, in order.
  • "LOOKUP|name|pos" returns [page, offset]: the physical page that holds position pos of name, and the offset inside that page.
  • "FREE|name" gives all pages of name back and forgets the sequence. The result is [the number of pages given back], which is [0] if name is not stored. A later APPEND to the same name starts a new sequence at position 0.

Two page rules for APPEND. First, all pages start free, and a new page is always the lowest-numbered free page, no matter in which order pages were freed. Second, an append is all or nothing: if it needs more new pages than are free, nothing is stored (not even the values that would fit in the last page's free room) and the result is [-1]. A refused append to a name that is not stored does not create it.

Function

pagedKvCache(pageSize: int, numPages: int, operations: String[]) → List<List<Integer>>

Examples

Example 1

pageSize = 2numPages = 4operations = ["APPEND|a|5,6,7","APPEND|b|8","APPEND|a|9,4","LOOKUP|a|4","READ|a|2|3","FREE|b"]return = [[0,1],[2],[3],[3,0],[7,9,4],[1]]

Each page holds 2 tokens. a needs 2 pages for 3 tokens and takes pages 0 and 1. b takes page 2. Token 9 fills the free spot in page 1, and token 4 needs a new page, so a takes page 3. Position 4 of a is entry 4 / 2 = 2 of its page table (page 3) at offset 4 % 2 = 0. Reading positions 2 to 4 starts in page 1 and continues in page 3. Freeing b gives back 1 page.

Example 2

pageSize = 3numPages = 2operations = ["APPEND|x|1,2,3,4","APPEND|y|7","APPEND|x|5,6","APPEND|x|8","READ|x|2|4","FREE|y"]return = [[0,1],[-1],[],[-1],[3,4,5,6],[0]]

x takes both pages. y needs a page and none is free, so nothing is stored and the result is [-1]. Tokens 5 and 6 fit in the 2 free spots of x's second page, so no page is taken. Token 8 would need a third page, so it is refused. y was never stored, so freeing it gives back 0 pages.

Example 3

pageSize = 2numPages = 4operations = ["APPEND|a|1,2","APPEND|b|3","APPEND|c|4,5,6","FREE|c","FREE|a","APPEND|d|7,8,9","APPEND|a|10","LOOKUP|d|2","READ|a|0|1"]return = [[0],[1],[2,3],[2],[1],[0,2],[3],[2,0],[10]]

After c and then a are freed, pages 0, 2 and 3 are free. d needs 2 pages and takes the two lowest-numbered ones, 0 and 2, no matter in which order they were freed. a was freed, so it starts again as a new sequence at position 0 and takes the last free page, 3.

Constraints

  • 1 <= pageSize <= 64
  • 1 <= numPages <= 1000
  • 1 <= operations.length <= 1000
  • Each operations[i] has one of the four forms above and at most 530 characters. Numbers are written in decimal without leading zeros.
  • Each sequence name has 1 to 10 characters, each a lowercase letter or a digit.
  • Each APPEND has 1 to 64 values, and each value is from 0 to 1000000.
  • For READ|name|start|count: name is stored, 0 <= start, 1 <= count, and start + count is at most the number of tokens stored for name.
  • For LOOKUP|name|pos: name is stored and 0 <= pos < the number of tokens stored for name.

More NVIDIA Phone Screen questions

  • Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
  • Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
  • Merge Multiple Sorted StreamsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Key-Value Store on a Block DeviceLambda · PHONE SCREEN
  • Design Authentication ManagerApple · PHONE SCREENApple interview questions
  • LLM Provider Pool FailoverPerplexity AI · PHONE SCREENPerplexity AI interview questions
  • ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
  • Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
  • Tiered Expiring Item StoreAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
  • Limit Order Book Matching EngineCitadel · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public List<List<Integer>> pagedKvCache(int pageSize, int numPages, String[] operations) {
        // Write your code here.
    }
}
Checking account…