Reported October 2026
OpenAIdesign

Incremental Hard Attention with a KV Cache

Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live OpenAI OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this OpenAI question is recomputing keys and values for the whole prefix at every step. Reported in October 2026, "Incremental Hard Attention with a KV Cache" is a design problem dressed up as ML. You get n token embeddings, n position embeddings, and square key and value weight matrices. At each step you add the new token's key and value to a cache and attend over what's stored. The example shows hard attention: the highest score wins and its value is returned. If you blank on the cache bookkeeping mid-assessment, StealthCoder runs invisibly on your desktop as a safety net.

The problem

Implement a deterministic incremental attention adapter. The input contains n token embeddings and n position embeddings, each of dimension d, plus square key and value weight matrices.
At step t:

Examples
Example 1
tokenEmbeddings = [[1,0],[1,1]]
positionEmbeddings = [[0,0],[0,0]]
keyWeights = [[1,0],[0,1]]
valueWeights = [[0,1],[1,0]]
return = [[0,1],[1,1]]
At each step, the newest key has the unique highest score. Values come from the separate value projection, not from the attention output.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is the cache. At step t, add token t and position t, project once with the key matrix and once with the value matrix, and append both to lists. Never touch earlier entries again. Then score the new query against every cached key and pick the max. That makes each step O(t*d) instead of redoing projections for the full prefix. The classic pitfall is the one in the example note: values come from the separate value projection, not from the attention output or the key. Mixing those up gives wrong results even when the argmax is right. Also watch tie-breaking, since the statement says deterministic but the visible text is truncated, so follow whatever rule the full prompt states. Use integer math if inputs are integers. If the live OA throws a spec detail at you and you freeze, StealthCoder gives you a working structure to check your own against.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Incremental Hard Attention with a KV Cache cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass OpenAI's OA.

OpenAI reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Incremental Hard Attention with a KV Cache FAQ

What's the core trick in the KV cache attention problem?+

Compute the key and value for each new token exactly once, append them to a cache, and reuse them on later steps. Each step then only scores the current query against stored keys. Recomputing the whole prefix every step is the naive approach and usually what gets flagged.

How hard is this OpenAI OA question really?+

The math is light. It's matrix-vector multiplication, a dot-product score, and an argmax. The difficulty is reading the spec carefully and keeping the cache state straight across steps. If you code cleanly and trace the example, it's very doable.

Where do the values come from in the example?+

From the separate value projection of the input, using the value weight matrix. The example explicitly says values do not come from the attention output. Keep key and value projections as two independent computations on the same input vector.

What input does each step project?+

The problem gives token and position embeddings of the same dimension d, so the natural input is their sum for that step. Check the full statement, since the visible text is cut off. Then multiply by the key and value matrices to get the entries you cache.

How do I prepare for this in 48 hours?+

Write a small class with an append-and-attend method, then hand-trace Example 1. Practice matrix-vector multiply and argmax with tie handling until it's automatic. Test a size-1 input and a tie case. Don't memorize anything beyond the cache pattern.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with OpenAI.

OA at OpenAI?
Invisible during screen share
Get it