Sure Profit on a Horse Race
Updated
Problem statement
One or more horses run a race, and exactly one of them wins. A $1 ticket on horse i pays back payouts[i] dollars in total (your dollar included) if that horse wins, and nothing if it loses.
You have one dollar. You may split it across the horses in any way, using fractions of a dollar, and you may also keep some or all of it. A stake of x dollars on a horse works like x tickets, so it pays back x × payouts[i] if that horse wins. Your profit is the money you end with minus the dollar you started with.
Return the largest profit you can guarantee, no matter which horse wins. If no split guarantees a positive profit, the answer is 0: keep the dollar.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
sureProfitPerDollar(payouts: int[]) → doubleExamples
Example 1
payouts = [2,4,6]return = 0.09090909090909091This is the interview case. Put 6/11 of the dollar on the first horse, 3/11 on the second and 2/11 on the third. Whichever horse wins, you get back 12/11: 6/11 × 2 = 3/11 × 4 = 2/11 × 6 = 12/11. The profit is 1/11, about 0.0909.
No plan does better. A dollar you keep comes back as one dollar. A dollar you spread in these same proportions comes back as 12/11 whichever horse wins, and no other way of splitting the bets guarantees more per dollar staked. Since 12/11 is more than 1, the best plan stakes the whole dollar.
Example 2
payouts = [3,5,7]return = 0.4788732394366197This is the interview case read the other way: 2, 4 and 6 dollars of profit on top of the $1 stake means payouts of 3, 5 and 7.
Now 1/3 + 1/5 + 1/7 = 71/105. Staking 1/3, 1/5 and 1/7 scaled by 105/71 uses exactly one dollar and pays back 105/71 whichever horse wins. The profit is 34/71, about 0.4789.
Example 3
payouts = [2,3,4]return = 0.0Here 1/2 + 1/3 + 1/4 = 13/12, which is more than 1. Staking a dollar so that it pays back the same amount whichever horse wins returns only 12/13 of it, a loss, while a dollar you keep stays a dollar. The best plan is not to bet, so the answer is 0.
Constraints
1 <= payouts.length <= 10001 <= payouts[i] <= 10^9
More Susquehanna International Group (SIG) Phone Screen questions
- Dice Sum That Is a Multiple of mPHONE SCREEN · Seen Nov 2026
- Find Median from Data StreamPHONE SCREEN · Seen Nov 2026
- Painting Arcs to Nearest Neighbors on a CirclePHONE SCREEN · Seen Sep 2026
- Filter Movies by Inclusive Year RangePHONE SCREEN · Seen Jul 2026
- Best Single Reroll for Five DicePHONE SCREEN · Seen Feb 2026
- Catching the Bus to the MoviePHONE SCREEN · Seen Jan 2026
- Two Dice Summing to a TargetPHONE SCREEN · Seen Jan 2026
- Median of Uniform Draws in an IntervalPHONE SCREEN · Seen Oct 2025
- One Number Is the Average of the Other TwoPHONE SCREEN · Seen Jun 2025
- Which Coin Pattern Shows Up FirstPHONE SCREEN · Seen May 2025
Similar questions at other companies
- Square Root FunctionCitadel · PHONE SCREENCitadel interview questions
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Convex Function MinimizationUber · PHONE SCREENUber interview questions
- Square Root with Newton IterationGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Minimum of a Convex FunctionRippling · PHONE SCREENRippling interview questions
- Minimum Full Glasses for an Exact Water VolumeMarshall Wace · PHONE SCREENMarshall Wace interview questions
- Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
- Percentile and Boundary QueriesDatadog · PHONE SCREENDatadog interview questions
- Categorical Sampling with Recorded DrawsMicrosoft · PHONE SCREENMicrosoft interview questions
- Pressure Chamber Linear InterpolationSpaceX · PHONE SCREENSpaceX interview questions