Passing Cards Around a Circle
Updated
Problem statement
n people sit around a round table, facing the middle, so each person has a neighbor on their left and a neighbor on their right. Everyone holds one card.
At the same moment, every person passes their card to one neighbor. Each person passes to their left neighbor with probability leftPercent / 100 and to their right neighbor otherwise. The choices are independent.
Return the expected number of people who hold no card after the cards are passed.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
expectedEmptyHanded(n: int, leftPercent: int) → doubleExamples
Example 1
n = 100leftPercent = 50return = 25.0This is the interview case. Look at one person. A card can only come from their two neighbors. They end up with nothing only if the neighbor on their left passes to the left (away from them) and the neighbor on their right passes to the right (also away). That happens with probability 1/2 × 1/2 = 1/4.
The expected count is the sum of every person's chance: 100 × 1/4 = 25.
Example 2
n = 3leftPercent = 50return = 0.75Each of the 3 people is empty-handed with probability 1/4, as above, so the answer is 3 × 1/4 = 0.75.
Example 3
n = 2leftPercent = 30return = 0.0With two people, each person's left and right neighbor is the same person, and that person's card comes to them whichever way it is passed. Nobody ends up empty-handed, so the answer is 0.
Constraints
2 <= n <= 10^90 <= leftPercent <= 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
- 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