Picked Player Who Lost
Updated
Problem statement
A contest has k players, numbered 0 to k - 1, where k = weights.length. Exactly one player wins. Player i wins with probability weights[i] / S, where S is the sum of all the weights.
Before the contest, you pick one player to cheer for, choosing each player with the same probability 1/k. After the contest, you learn that the player you picked did not win.
Return the probability that the player you picked is player target. Answers within 10^-9 of the exact value are accepted.
Function
pickedContestantProbability(weights: int[], target: int) → doubleExamples
Example 1
weights = [12,3,1]target = 0return = 0.125This is the interview case. The weights add up to 16, so the players win with probability 3/4, 3/16 and 1/16. You pick each player with probability 1/3. The chance that you picked player 0 and they lost is 1/3 * 1/4 = 1/12. The chance that your player lost at all is 1/3 * (1/4 + 13/16 + 15/16) = 1/3 * 2 = 2/3. The answer is (1/12) / (2/3) = 1/8 = 0.125.
Example 2
weights = [12,3,1]target = 2return = 0.46875Same contest, but now we ask about the weakest player. They lose with probability 15/16, so the answer is (1/3 * 15/16) / (2/3) = 15/32 = 0.46875.
Example 3
weights = [1,3]target = 0return = 0.75Player 0 wins with probability 1/4 and loses with probability 3/4. Player 1 loses with probability 1/4. The answer is (1/2 * 3/4) / (1/2 * 3/4 + 1/2 * 1/4) = 3/4 = 0.75.
Constraints
2 <= weights.length <= 10001 <= weights[i] <= 10^90 <= target < weights.length
More Susquehanna International Group (SIG) Online Assessment questions
- Catch Fish with Reusable BaitsOA · Seen Nov 2026
- Bold Play to Reach a GoalOA · Seen Nov 2026
- Cats, Truth and Who Has MoreOA · Seen Nov 2026
- Counting Cows by Their LegsOA · Seen Nov 2026
- Enough Muffins for the LineOA · Seen Nov 2026
- Expected Consecutive Pairs Among Chosen NumbersOA · Seen Nov 2026
- Four-by-Four Boundary GridOA · Seen Nov 2026
- Frog Paths Without Long RunsOA · Seen Nov 2026
- Higher Roll, or Lose the SumOA · Seen Nov 2026
- Is a Popular Story Fake?OA · Seen Nov 2026
Similar questions at other companies
- Count Valid Square PairsAuxoAI · OA
- Server InvestmentRippling · OARippling interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Unique Integers That Sum to ZeroNVIDIA · OANVIDIA interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Maximum Student-Teacher DistanceChubb · OAChubb interview questions
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Minimum Password IncrementsAccenture · OAAccenture interview questions