Knockout Tournament Win Probability
Updated
Problem statement
There are n teams numbered from 0 to n - 1, where n is a power of two. Their positions in a fixed single-elimination bracket are their numeric order.
The matrix winProbability gives the outcome probability of every possible match: winProbability[i][j] is the probability that team i defeats team j. Match outcomes are independent.
In round one, teams 0 and 1 play, teams 2 and 3 play, and so on. In every later round, the winner of the left half of each bracket block plays the winner of its right half. Return the probability that team target wins the tournament.
Function
tournamentWinProbability(winProbability: double[][], target: int) → doubleExamples
Example 1
winProbability = [[0.0,0.7],[0.3,0.0]]target = 0return = 0.7The tournament has one match, which team 0 wins with probability 0.7.
Example 2
winProbability = [[0.0,1.0,0.6,0.8],[0.0,0.0,0.5,0.5],[0.4,0.5,0.0,1.0],[0.2,0.5,0.0,0.0]]target = 0return = 0.6Teams 0 and 2 win their first-round matches with probability 1. Team 0 then defeats team 2 with probability 0.6.
Example 3
winProbability = [[0.0,0.5,0.8,0.4],[0.5,0.0,0.5,0.5],[0.2,0.5,0.0,0.25],[0.6,0.5,0.75,0.0]]target = 0return = 0.25Team 0 reaches the final with probability 0.5. Team 2 reaches it with probability 0.25 and team 3 with probability 0.75, so the result is 0.5 * (0.25 * 0.8 + 0.75 * 0.4) = 0.25.
Constraints
1 <= n <= 128andnis a power of two.winProbability.length = nand every row has lengthn.0 <= winProbability[i][j] <= 1.- For distinct teams,
winProbability[i][j] + winProbability[j][i] = 1. winProbability[i][i] = 0.0 <= target < n.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Deterministic K-Means AssignmentsLyft · PHONE SCREENLyft interview questions
- Online Chess Move ValidationOpenAI · PHONE SCREENOpenAI interview questions
- Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Scaled Dot-Product AttentionAmazon · PHONE SCREEN
- Deterministic K-Means AssignmentsMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Implement K-Means ClusteringApple · PHONE SCREENApple interview questions
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions