Odd First-Success Roll Probability
Updated
Problem statement
You roll a fair die with faces numbered 1 through sides. Every face is equally likely, and each roll is independent of the others. Keep rolling until the die first shows the face sides.
Let N be the total number of rolls. Count from 1, and include the roll that showed sides. Return the probability that N is odd.
The classic version of this question uses a six-sided die and waits for the first 6. Here sides is an input, so the die size can change. Complete oddFirstSuccessProbability(sides). It returns a double. Do not round it.
Your answer is accepted when abs(actual-expected) <= 1e-9 * max(1,abs(expected)).
Function
oddFirstSuccessProbability(sides: int) → doubleExamples
Example 1
sides = 6return = 0.5454545454545454The exact probability is 6/11.
Example 2
sides = 2return = 0.6666666666666666The exact probability is 2/3.
Example 3
sides = 3return = 0.6The exact probability is 3/5.
Constraints
2 <= sides <= 10^6- The die is fair, and the rolls are independent.
- The count of rolls includes the roll that shows
sides.
More IMC Trading Phone Screen questions
- Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
- Uniform Variables: Smaller Below Larger SquaredPHONE SCREEN · Seen Mar 2026
- Combination Sum with Unlimited ReusePHONE SCREEN · Seen Dec 2025
- Valid Range of a Three-Outcome Probability ParameterPHONE SCREEN · Seen Dec 2025
- Expected Fishing CatchPHONE SCREEN · Seen Dec 2025
- Count Routes Through a City GridPHONE SCREEN · Seen Nov 2024
- Expected City Arrival and Return DaysPHONE SCREEN · Seen Nov 2024
- Stationary City Population SharesPHONE SCREEN · Seen Nov 2024
- Maximum Falling Path SumPHONE SCREEN · Seen Nov 2024
- Trading Profit Percentage ChangePHONE SCREEN · Seen Feb 2024
Similar questions at other companies
- Parking Fee CalculatorBreeze · PHONE SCREEN
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Sqrt(x)LinkedIn · PHONE SCREENLinkedIn interview questions
- 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