Coin With Randomly Marked Faces
Updated
Problem statement
A special die has s faces; a coin is the case s = 2. Before the game, each face is marked H with probability p percent and T otherwise, independently. You cannot see the marks.
Each toss shows one of the s faces uniformly at random, independently of other tosses. You toss the die t times and see h tosses showing H and t - h showing T, in some order.
Return the probability that the next toss shows H.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
nextHeadsChance(s: int, p: int, t: int, h: int) → doubleExamples
Example 1
s = 2p = 50t = 1h = 1return = 0.75This is the interview coin. It has two H sides with chance 1/4, one H side with chance 1/2, and no H side with chance 1/4.
The first toss shows H with chance 1/4 × 1 + 1/2 × 1/2 = 1/2. Both tosses show H with chance 1/4 × 1 + 1/2 × 1/4 = 3/8. So the answer is (3/8) / (1/2) = 3/4.
Example 2
s = 2p = 50t = 2h = 2return = 0.8333333333333334Two heads seen. The two-H coin gives this with chance 1/4 × 1 = 1/4 and the one-H coin with chance 1/2 × 1/4 = 1/8. The next toss is H with chance (1/4 × 1 + 1/8 × 1/2) / (1/4 + 1/8) = (5/16) / (3/8) = 5/6.
Example 3
s = 2p = 30t = 1h = 1return = 0.65Each side is H with chance 0.3. The coin has one H side with chance 2 × 0.3 × 0.7 = 0.42 and two with chance 0.09. Seeing one H gives weights 0.42 × 1/2 = 0.21 and 0.09 × 1 = 0.09. The answer is (0.21 × 1/2 + 0.09 × 1) / 0.30 = 0.65.
Constraints
2 <= s <= 1001 <= p <= 991 <= t <= 10000 <= h <= t
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
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Logistic Regression with Gradient DescentYahoo · PHONE SCREENYahoo interview questions
- Evaluate an Arithmetic Expression Written in WordsBrex · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Integer to English Words in USD and INR StylesVeeam · PHONE SCREEN
- Adaptive Calibration ErrorOpenAI · PHONE SCREENOpenAI interview questions
- Sum of Smallest Non-DivisorsThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Square Root FunctionCitadel · PHONE SCREENCitadel interview questions
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions