FastPrepTwo Ranked Teams Meeting in a Random Bracket
Problems/Two Ranked Teams Meeting in a Random Bracket

Two Ranked Teams Meeting in a Random Bracket

Optiver logoOptiver● MediumFULLTIMEOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One report, posted in 2026 about an Optiver online assessment for a full-time quantitative researcher role, lists a set of probability questions; this problem is built on one of them.

In that question 64 teams with ranks are placed into a knockout bracket at random, and the better-ranked team wins every match. It asks for the chance that the teams ranked 2 and 3 face each other in a semifinal, and gives no answer.

Our choices: the bracket is fixed and every order of the teams on it is equally likely (no seeding that keeps top teams apart); the number of teams, the two ranks and the round are inputs (up to 2^20 teams, any two ranks, any round from the opening round to the final); and the result is a decimal accepted within 10^-6. The reported case is Example 1; we chose the other examples and all limits.

Our version is about 85% the same as the reported question.

A knockout tournament has teams teams, ranked from 1 (strongest) to teams (weakest). When two teams play, the team with the lower rank number wins and stays in; the other team is out.

The bracket has teams lines in a fixed order. The opening round pairs line 1 with line 2, line 3 with line 4, and so forth up to the last two lines. Each later round pairs the winners of neighbouring blocks: the team that comes out of lines 1-2 meets the team that comes out of lines 3-4, the team from lines 1-4 meets the team from lines 5-8, and this goes on until one team is left.

Before the tournament starts, the teams are put on the lines at random: every one of the teams! orders is equally likely. There is no seeding that keeps the strong teams apart.

A round is named by teamsLeft, the number of teams still in the tournament when that round starts. So teamsLeft = teams is the opening round, teamsLeft = 4 is the semifinal and teamsLeft = 2 is the final.

Find the probability that the teams ranked rankA and rankB play each other in the round named by teamsLeft, and return it.

Function

meetProbability(teams: int, rankA: int, rankB: int, teamsLeft: int) → double

Examples

Example 1

teams = 64rankA = 2rankB = 3teamsLeft = 4return = 0.13108038914490527

Put rank 2 on any line. The semifinal pairs two blocks of 16 lines, so rank 3 has to land in the other block of 16 inside the same half: 16 of the 63 open lines. Rank 1 must then land outside that half, or it would knock one of them out first: 32 of the 62 lines left. The chance is (16/63) · (32/62) = 256/1953, about 0.131080.

Example 2

teams = 8rankA = 2rankB = 3teamsLeft = 2return = 0.0

A final between ranks 2 and 3 needs each of them to win a half. Rank 1 sits in one of those halves and beats whoever is there, so this never happens: the answer is 0.

Example 3

teams = 8rankA = 3rankB = 5teamsLeft = 4return = 0.08571428571428572

The round with 4 teams left pairs two blocks of 2 lines. Rank 5 lands in the block next to rank 3 with chance 2/7. Ranks 1 and 2 must both sit on the 4 lines outside those blocks: 4/6 · 3/5. Rank 4 may share rank 3's block (rank 3 beats it) but not rank 5's: 3 of the 4 lines left. Altogether (2/7) · (4/6) · (3/5) · (3/4) = 3/35, about 0.085714.

Constraints

  • teams = 2^k for a whole number k with 1 <= k <= 20, so 2 <= teams <= 1048576.
  • 1 <= rankA < rankB <= teams
  • teamsLeft = 2^j for a whole number j with 1 <= j <= k, so 2 <= teamsLeft <= teams.
  • Your answer is accepted when it differs from the correct probability by at most 10^-6.

More Optiver Online Assessment questions

  • Chance a Die Game Balance Reaches ZeroOA · Seen Dec 2026
  • Chance a Hand of Cards Multiplies to More Than a ThresholdOA · Seen Dec 2026
  • Chance a Sum of Random Draws Has a Given Number of DigitsOA · Seen Dec 2026
  • Expected Draws to Remove All Green CountersOA · Seen Dec 2026
  • Expected Profit of a Doubling Betting SystemOA · Seen Dec 2026
  • Expected Steps Until a Random Walk Gets Far From ZeroOA · Seen Dec 2026
  • Rolling Until One Face's Own Total Passes a ThresholdOA · Seen Dec 2026
  • Overheat Prevention ControllerOA · Seen Nov 2026
  • Power Cell BankOA · Seen Nov 2026
  • Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026

Similar questions at other companies

  • Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions
  • Get Triplet CountIBM · OAIBM interview questions
  • Count Fancy NumbersHudson River Trading · OAHudson River Trading interview questions
  • Count Numbers with the Same Set-Bit CountMicrosoft · OAMicrosoft interview questions
  • Count Reverse-Digit PairsVisa · OAVisa interview questions
  • Get Triplet CountPoint72 · OAPoint72 interview questions
  • Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
  • Color a Grid with No Monochromatic Row or ColumnIntuit · OAIntuit interview questions
  • Product of Subset MaximaArcesium · OAArcesium interview questions

Optiver interview experiences

  • Optiver SWE Intern OA: CPU Temperature Simulation: 1 Experience
  • Optiver Trading Intern Market-Making Games: 1 Experience
  • Optiver Quant Trader Intern Technical Interview: 1 Experience
  • Optiver SWE Intern System Design Interview: 15 Experiences
All Optiver interview questionsSee Optiver hiring insights
Saved
class Solution {
    public double meetProbability(int teams, int rankA, int rankB, int teamsLeft) {
        // Write your code here.
    }
}
Checking account…