FastPrepExpected People Met Before Someone Taller
Problems/Expected People Met Before Someone Taller

Expected People Met Before Someone Taller

Hudson River Trading logoHudson River Trading● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in two Hudson River Trading algorithm developer intern interviews on probability. The task was the average count of people you see after one person, until you reach a taller one.

The reports do not say how many people there are. With no end to the crowd the expected count is infinite, so here there are n people and the count stops at the last one. Neither the person you start with nor the taller one is counted.

Our version is about 75% the same as the reported question.

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) → double

Examples

Example 1

n = 3return = 0.8333333333

Label 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.0000000000

Nobody comes after the first person, so the count is always 0.

Example 3

n = 4return = 1.0833333333

Adding 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^-9 of 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

Interview reports that mention this question

  • Hudson River Trading interviews · 2022
  • Hudson River Trading interviews · 2023

Hudson River Trading interview experiences

  • Hudson River Trading Data Science Interviews: 2 Experiences
  • Hudson River Trading interviews · 2021
  • Hudson River Trading OA · 2021
  • Hudson River Trading OA · 2022
All Hudson River Trading interview questionsSee Hudson River Trading hiring insights
Saved
class Solution {
    public double expectedPeopleBeforeTaller(int n) {
        // Write your code here.
    }
}
Checking account…