Numerically Stable Softmax
Updated
Problem statement
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 Online Assessment questions
- 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
- Minimum Euclidean Distance Between PointsOA · Seen Jun 2026
- Rotate a Rectangular Image ClockwiseOA · Seen Jun 2026
- Triangle Flags from Adjacent ElementsOA · Seen Jun 2026
Similar questions at other companies
- Last Object to Fall Off the TableConfluent · OAConfluent interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Power-of-Two Removal OperationsIBM · OAIBM interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions