FastPrepNumerically Stable Softmax
Problems/Numerically Stable Softmax

Numerically Stable Softmax

Luma AI logoLuma AI● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: A first-hand Luma AI assessment provides the softmax callable, formula, library limits, and numerical-stability requirement. The practice task matches the report at about 99%.

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.

More Luma AI problems

  • Build a Gaussian Blur KernelOA · Seen Jun 2026
  • Center Crop a Grayscale ImageOA · Seen Jun 2026
  • Impute Missing Values and Normalize ColumnsOA · Seen Jun 2026
All Luma AI interview questionsSee Luma AI hiring insights
Saved
public double[] softmax(double[] logits) {
    // Return stable softmax probabilities.
}
Checking account…