Expected People Met Before Someone Taller
Updated
Problem statement
Return the expected number of people you meet after the first person and before anyone taller than that first person, when you meet n people one at a time in a uniformly random order.
All n people have different heights. If nobody is taller than the first person, the count is all n - 1 other people.
Function
expectedPeopleBeforeTaller(n: int) → doubleExamples
Example 1
n = 3return = 0.8333333333Label the heights 1 (shortest) to 3 (tallest). Of the 6 equally likely orders, 2, 1, 3 gives a count of 1, the two orders that start with 3 give 2 each and the other three give 0, so the expected count is 5/6, about 0.8333333333.
Example 2
n = 1return = 0.0000000000Nobody comes after the first person, so the count is always 0.
Example 3
n = 4return = 1.0833333333Adding up the counts over all 24 equally likely orders gives 26, so the expected count is 26/24 = 13/12, about 1.0833333333.
Constraints
1 <= n <= 10^6- 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
- 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