As reported: LinkedIn AI Engineer (IC2) phone screen, Dec 2025 — an hour of ML theory and light coding; the coding question was to compute the mean of an infinite data stream.
Numbers arrive one at a time from a stream that never ends. Implement a class that reports the mean of everything seen so far:
StreamMean()creates an empty tracker.add(x)takes the next number of the stream.mean()returns the mean of all numbers added so far.
Use O(1) memory: the stream cannot be stored.
Example
add(5) mean() → 5.0
add(10) mean() → 7.5
add(15) mean() → 10.0
Constraints: −10^9 ≤ x ≤ 10^9; mean() is called only after at least one add; up to 6 × 10^4 numbers per test.
Code runner format: one JSON line: the numbers of the stream. Implement StreamMean (add and mean; in Go Constructor, Add, Mean). The harness calls add for each number and mean() after every call, compares each answer with the exact mean (relative tolerance 10^-6) and prints "ok", or the first wrong answer.
Clarifications
- An endless stream means a running sum can grow without bound; keep the state small and numerically safe.