Reported June 2026
Luma AImath

Numerically Stable Softmax

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

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

The trap in Luma AI's Numerically Stable Softmax, reported in June 2026, is a single line that looks right and still fails. Compute exp(1000) directly and you get infinity, then NaN once you divide. The fix is old and short: subtract the max logit before exponentiating. It's an array and math problem with a tiny input size, so the OA is checking whether you know the stability trick, not whether you can grind. If you're taking it in the next day or two, learn this one cold. StealthCoder sits invisible on your screen as a safety net if you blank on the details during the live OA.

The problem

Given a nonempty array of finite logits, return its softmax probabilities in the same order.
Compute the mathematically equivalent maximum-shifted form so large logits do not overflow.

Function
softmax(logits: double[]) → double[]

Examples
Example 1
logits = [1.0,2.0,3.0]
return = [0.09003057317038046,0.24472847105479764,0.6652409557748218]
Subtracting 3 keeps all exponential arguments nonpositive.

Constraints
1 <= logits.length <= 200.
-1000 <= logits[i] <= 1000.
Results use absolute tolerance 1e-12.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: softmax(x) equals softmax(x - max(x)), because the shared factor exp(-max) cancels in the ratio. After shifting, every exponent is at most 0, so every exp value lands in (0, 1] and the largest term is exactly 1. No overflow possible. Steps: find the max, compute exp(x[i] - max) for each element, sum them, divide each by the sum. The common pitfall is skipping the shift because the sample [1,2,3] passes without it. The constraints allow logits up to 1000, and exp(1000) overflows a double, so hidden tests will punish the naive version. Another pitfall is recomputing exp twice or summing in a sloppy way. Store the exponentials once. Tolerance is 1e-12, so use doubles throughout and don't round early. If you freeze on the details during the live OA, StealthCoder is the hedge that hands you the shifted form instantly.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Numerically Stable Softmax 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 would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Luma AI reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Numerically Stable Softmax FAQ

What's the trick in Numerically Stable Softmax?+

Subtract the maximum logit from every element before calling exp. The result is mathematically identical because the constant factor cancels in the ratio, but every exponent becomes nonpositive, so nothing overflows. Then divide each exponential by their sum.

Why does the naive version fail if the example passes?+

The example uses logits 1, 2, 3, which are tiny. The constraints allow values up to 1000, and exp(1000) overflows a double to infinity. Infinity divided by infinity gives NaN. Hidden tests with large logits will catch it.

How hard is this one really?+

Easy to code, easy to get wrong if you've never seen the stability trick. It's about ten lines. The difficulty is knowing the shift exists and remembering to apply it before exponentiating, not any data structure or algorithm.

Do I need to worry about underflow after the shift?+

Very negative shifted values can underflow to 0, but that's fine. The max element always becomes exp(0) = 1, so the sum is at least 1 and you never divide by zero. Tiny terms vanishing stays well within the 1e-12 tolerance.

How do I prepare for this in 48 hours?+

Write softmax from memory twice, once naive and once shifted, and test with [1000, 1000, 1000] and [-1000, 0, 1000]. Check the output sums to 1. That covers the edge cases. Also practice log-sum-exp, since it uses the same idea.

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

OA at Luma AI?
Invisible during screen share
Get it