Reported July 2026
OpenAImath

Streaming Entropy, Part 4: Stable Streaming Entropy

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 OpenAI OA reported in July 2026 is Part 4 of a streaming entropy sequence, and the constraint that kills brute force isn't speed. It's memory and overflow. Logits arrive in blocks, they can hit 10^9, and you can't store them, concatenate them, or do a first pass for the max. So it's a one-pass numerically stable softmax entropy with a running maximum. The math is short once you see it. The trap is the rescale when a new max shows up mid-stream. If you blank on the algebra live, StealthCoder is the safety net running invisibly on the assessment.

The problem

Streaming Entropy Interview Sequence
This is Part 4 of one four-part ML coding exercise.
Streaming Entropy, Part 1: Batch Entropy
Streaming Entropy, Part 2: Numerically Stable Entropy
Streaming Entropy, Part 3: Block-wise Entropy
Streaming Entropy, Part 4: Stable Streaming Entropy
The logits of one softmax distribution arrive in consecutive, non-empty blocks. Concatenating the blocks in order would produce the complete stream x.
For the full stream,
p[i] = exp(x[i]) / sum(exp(x[j]))
H = -sum(p[i] * ln(p[i]))
The logits may be extremely large or small. Direct exponentiation can overflow, and a later block may contain a new maximum that changes the scale of every previously accumulated exponential.
Streaming Requirements
Process the blocks in order and return the non-negative entropy over every logit in the stream.
Do not concatenate the blocks, retain all logits, materialize the probability vector, or make a preliminary pass to find the global maximum. Keep a running maximum and constant-size aggregate state. Whenever the running maximum increases, rescale the previously accumulated state before merging the new block.
Your implementation must run in O(n) time and use O(1) auxiliary space, where n is the total number of logits.
An answer is accepted when its absolute or relative error is at most 1e-6.
This completes the four-part Streaming Entropy interview sequence.

Function
streamingEntropy(blocks: double[][]) → double

Examples
Example 1
blocks = [[0.0], [0.0]]
return = 0.6931471805599453
The two logits produce probabilities [0.5, 0.5]. Their entropy is ln(2).
Example 2
blocks = [[0.0], [1.0986122886681098]]
return = 0.5623351446188083
The second logit is ln(3), so the probabilities are [0.25, 0.75]. The running maximum also increases after the first block.
Example 3
blocks = [[1000.0, 1000.0], [-1000.0]]
return = 0.6931471805599453
Directly evaluating exp(1000) overflows. A stable running scale keeps the first two outcomes at probability 0.5 each while the third is negligible.

Constraints
1 <= blocks.length <= 10^4
1 <= blocks[i].length
The total number of logits across all blocks is at most 2 * 10^5.
Every logit is finite and lies in [-10^9, 10^9].
Use the natural logarithm.
Process the stream in one pass over the blocks.
Use O(n) time and O(1) auxiliary space.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Track three values: running max m, S = sum(exp(x - m)), and T = sum(exp(x - m) * (x - m)). Entropy is H = ln(S) - T/S. When a block brings a new max m', shift d = m' - m. Rescale: S = S * exp(-d), and T = exp(-d) * (T - d * S_old). Then add the new block's terms using m'. The common pitfall is rescaling S but forgetting that T has a linear (x - m) factor, so it needs the extra d * S term. Another is initializing m to 0 instead of negative infinity, which breaks all-negative streams. Handle the first element so you never compute exp(-inf - -inf). Clamp tiny negative results to 0. If you freeze on the T update, StealthCoder is the hedge on the live OA, because it reads the problem and hands you the recurrence.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Streaming Entropy, Part 4: Stable Streaming Entropy 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Streaming Entropy, Part 4: Stable Streaming Entropy FAQ

What's the trick in Streaming Entropy Part 4?+

Keep a running max m, a sum S of exp(x - m), and a weighted sum T of exp(x - m) times (x - m). The answer is ln(S) - T/S. When m rises, rescale both S and T. That's the whole problem. Everything else is careful bookkeeping.

How do I rescale T when the max changes?+

With d = newMax - oldMax, S becomes S * exp(-d). T becomes exp(-d) * (T - d * S_old), because each old term's (x - m) shifts by -d. Use the old S in that formula, not the already-updated one. Mixing them up is the classic bug.

Why can't I just subtract the global max first?+

The problem forbids a preliminary pass and forbids retaining logits. You only see each block once, so the global max isn't known up front. The running max with rescaling gives the same result in one pass using O(1) extra space.

What edge cases should I test before submitting?+

Test the examples: two zeros giving ln(2), the ln(3) case where the max increases after block one, and [1000, 1000] then [-1000]. Also try a single logit (entropy 0), all very negative logits, and a later block with a huge new max. Clamp tiny negatives to 0.

How do I prepare for this in 48 hours?+

Write the online softmax and log-sum-exp from memory, then extend it with the T term. Derive the rescale once on paper so you trust it. Code it against the three examples. Parts 1 to 3 are just stepping stones, so focus on this final merged version.

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