Dice Match Game
Updated
Problem statement
You roll myDice fair dice, and the interviewer rolls theirDice fair dice. Every die has sides faces numbered 1 to sides, and all the dice are independent.
- If at least one number shows up on both sides (on one of your dice and on one of theirs), you pay the interviewer
$1. - Otherwise, when no number is shared, the interviewer pays you
$1.
Return your expected gain from one game, in dollars. A positive value means the game is worth playing.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
matchGameExpectedGain(sides: int, myDice: int, theirDice: int) → doubleExamples
Example 1
sides = 6myDice = 2theirDice = 2return = -0.027777777777777776This is the interview game: two normal dice each.
The interviewer's two dice show the same number with chance 1/6. Then both of yours miss that number with chance (5/6)^2 = 25/36. With chance 5/6 their dice show two different numbers, and both of yours miss both with chance (4/6)^2 = 16/36.
So no number is shared with chance 1/6 × 25/36 + 5/6 × 16/36 = 105/216, a little under one half. Your expected gain is 105/216 - 111/216 = -6/216 = -1/36, about -0.0278. Do not play.
Example 2
sides = 6myDice = 2theirDice = 1return = 0.3888888888888889If the interviewer rolls just one die, both of yours miss its number with chance 25/36. The expected gain is 25/36 - 11/36 = 14/36 = 7/18, about 0.3889, so this version is worth playing.
Example 3
sides = 2myDice = 1theirDice = 1return = 0.0A two-faced die, one each. The numbers match with chance 1/2, so you win and lose $1 equally often and the expected gain is 0.
Constraints
2 <= sides <= 1001 <= myDice, theirDice <= 100
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
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Election District Budget Allocation AnalysisIMC Trading · PHONE SCREENIMC Trading interview questions
- Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Find Encrypted NumberAmazon · OA
- Valid PasswordsMathWorks · OAMathWorks interview questions
- Coloring HousesSnowflake · OASnowflake interview questions