Taste-Test Claim: Chance of Guessing This Well
Updated
Problem statement
Return the probability that a person who is only guessing gets k or more right out of n candies, when each guess is right with probability 1/c, independently for each candy.
This tests a claim. Someone says they can tell the color of a chocolate candy by taste alone. There are c colors. In a test they taste n candies, name a color for each one, and get k of them right.
Note: this is the one-sided p-value for the claim. A small value means pure guessing rarely does this well, which counts as evidence for the claim.
Function
tasteTestPValue(c: int, n: int, k: int) → doubleExamples
Example 1
c = 5n = 3k = 2return = 0.1040000000Exactly two right has probability 3 * 0.2^2 * 0.8 = 0.096, and three right has 0.2^3 = 0.008. The total is 0.104, so guessing does this well about one time in ten. That is weak evidence for the claim.
Example 2
c = 5n = 100k = 30return = 0.0112489787A guesser expects 100 * 0.2 = 20 right. Getting 30 or more has probability about 0.0112, so guessing rarely does this well. That is much stronger evidence for the claim.
Example 3
c = 2n = 4k = 0return = 1.0000000000Every result has 0 or more right answers, so the probability is 1.
Constraints
2 <= c <= 1001 <= n <= 10000 <= k <= n- Answers within
10^-9of the correct value are accepted.
More Hudson River Trading Phone Screen questions
- Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
- Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
- Tilting Maze BallPHONE SCREEN · Seen Oct 2026
- Tiered Expiring Item StorePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Mean vs Median: Chance of Missing the CenterPHONE SCREEN · Seen Sep 2026
- Market Data Signal WatcherPHONE SCREEN · Seen Jul 2026
- Integer to String Without Built-insPHONE SCREEN · Seen May 2026
- Contact Tracing Through Timed MeetingsPHONE SCREEN · Seen Nov 2024
- Polydivisible Pandigital NumbersPHONE SCREEN · Seen Feb 2024
- Defragment a Buffer of ObjectsPHONE SCREEN · Seen Nov 2023
Similar questions at other companies
- Best Single Reroll for Five DiceSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Expected Rank of the Hired CandidateJane Street · PHONE SCREENJane Street interview questions
- 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