Two Dice Summing to a Target
Updated
Problem statement
You roll two fair dice. Each die has faces faces numbered 1 to faces, each face comes up with probability 1/faces, and the two dice are independent.
Return the probability that the two numbers add up to exactly target. If no pair of faces adds up to target, the probability is 0.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
twoDiceTargetSumProbability(faces: int, target: int) → doubleExamples
Example 1
faces = 6target = 7return = 0.16666666666666666Two ordinary six-sided dice have 36 equally likely results. Six of them add up to 7: 1+6, 2+5, 3+4, 4+3, 5+2 and 6+1. The answer is 6/36 = 1/6.
Example 2
faces = 6target = 10return = 0.08333333333333333Three of the 36 results add up to 10: 4+6, 5+5 and 6+4. The answer is 3/36 = 1/12, about 0.0833.
Example 3
faces = 4target = 9return = 0.0Two four-sided dice add up to at most 4 + 4 = 8, so a sum of 9 is impossible and the answer is 0.
Constraints
1 <= faces <= 10^51 <= target <= 2 * 10^5
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
- 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
- Random Points Inside One ArcPHONE SCREEN · Seen Jan 2025
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Circular Primes Below a LimitAmazon · PHONE SCREEN
- Palindrome NumberKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- Streaming AverageXantium · PHONE SCREEN
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Newton Square Root to a Guaranteed ToleranceSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions