Mean vs Median: Chance of Missing the Center
Updated
Problem statement
Return [meanMiss, medianMiss]: the probabilities that the sample mean and the sample median of n independent draws of a random value X differ from its center mu by more than eps.
With probability p, X equals mu exactly. Otherwise, X is drawn from a normal distribution with mean mu and standard deviation 1.
- Sample mean: the average of the
nvalues. - Sample median: the value at position
ceil(n / 2)when the values are sorted from smallest to largest. For oddnthis is the middle value. For evennit is the lower of the two middle values.
Note: both probabilities are the same for every value of mu, so mu is not an input.
Function
meanMedianMissProbabilities(p: double, n: int, eps: double) → double[]Examples
Example 1
p = 0.2n = 80eps = 0.1return = [0.3169299193,0.0166651838]The count of normal values is binomial with 80 trials and chance 0.8, and averaging the mean's normal miss chance over that count gives about 0.3169299193, close to the quick estimate 0.3173 from the overall standard deviation sqrt(0.8 / 80) = 0.1. Each value lands above mu + 0.1 with chance about 0.3681377 and below mu - 0.1 with the same chance, so the 40th smallest value misses when at least 41 values land above or at least 40 land below, about 0.0058454 + 0.0108198 = 0.0166651838.
Example 2
p = 0.5n = 3eps = 0.5return = [0.2067315672,0.1281074400]The mean is exact with no normal values (chance 1/8) and misses with chance about 0.1336144, 0.2888444 and 0.3864762 with 1, 2 or 3 (chances 3/8, 3/8 and 1/8), for about 0.2067315672 in total. Each value is above mu + 0.5 with chance q, about 0.1542688, so the middle value misses on each side with chance 3 * q^2 * (1 - q) + q^3, about 0.0640537, for about 0.1281074400 in total.
Example 3
p = 0.5n = 2eps = 0.5return = [0.2785302845,0.3085375387]The median is the smaller value, which is above mu + 0.5 only if both values are and below mu - 0.5 if either one is, so with q about 0.1542688 it misses with chance q^2 + 1 - (1 - q)^2 = 2 * q, about 0.3085375387. The mean is exact with no normal values (chance 1/4) and misses with chance about 0.3173105 with one (chance 1/2) or 0.4795001 with two (chance 1/4), for about 0.2785302845 in total.
Constraints
0 <= p <= 11 <= n <= 2000.01 <= eps <= 5- Each returned value within
10^-5of the correct value is 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
- 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
- Expected People Met Before Someone TallerPHONE 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