Friends Apart at a Round Table
Updated
Problem statement
A round table has n seats. Each seat has two neighbors: the seats on its left and on its right, and the first and last seats are neighbors too.
k friends sit down at random: every set of k seats is equally likely to be the set they take. Any other seats may be filled by strangers, which does not matter here.
Return the probability that no two friends sit in neighboring seats.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
noFriendsAdjacentProbability(n: int, k: int) → doubleExamples
Example 1
n = 8k = 3return = 0.2857142857142857This is the first interview table. Put one friend in seat 1. Seats 2 and 8 are now banned, so the other two friends need two seats from 3, 4, 5, 6, 7 that are not side by side.
There are C(4, 2) = 6 such pairs, out of C(7, 2) = 21 pairs of the other seats. The answer is 6/21 = 2/7, about 0.2857.
Example 2
n = 10k = 3return = 0.4166666666666667This is the second interview table. Put one friend in seat 1; the other two friends need two seats from 3 to 9 that are not side by side. That is C(6, 2) = 15 of the C(9, 2) = 36 pairs, so the answer is 15/36 = 5/12, about 0.4167.
The interview asked for the chance that at least two friends sit together, which is 1 - 5/12 = 7/12, about 0.5833.
Example 3
n = 6k = 3return = 0.1Three friends at six seats can only avoid each other by taking every other seat: seats 1, 3, 5 or seats 2, 4, 6. That is 2 of the C(6, 3) = 20 seat sets, so the answer is 2/20 = 0.1.
Constraints
3 <= n <= 10^61 <= k <= n
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
- Revolver: Will the Next Shot Fire?Tower Research Capital · PHONE SCREEN
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Expected Fake-Name CollisionsMercor · PHONE SCREENMercor interview questions
- Election District Budget Allocation AnalysisIMC Trading · PHONE SCREENIMC Trading interview questions
- Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
- Extra Coin Win ProbabilityMicrosoft · PHONE SCREENMicrosoft interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
- Get Triplet CountIBM · OAIBM interview questions