Estimating Distinct Viewers From the Smallest Hash Values

Last updated: November 29, 2026

Quick Overview

A Reels analytics service must estimate distinct viewers per video over streams with billions of events, keeping only a small fixed amount of memory per video. Explain the k-minimum-values estimator, why (k - 1) divided by the k-th smallest hash is unbiased, and how its error scales with k.

Meta
Statistics & Math
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Statistics & Math
Hard

0

0

0 solved


A Reels analytics service must estimate distinct viewers per video over streams with billions of events, keeping only a small fixed amount of memory per video. Explain the k-minimum-values estimator, why (k - 1) divided by the k-th smallest hash is unbiased, and how its error scales with k.

Meta's analytics infrastructure uses sketches for distinct counts at scale, and engineers on these systems should understand the statistics behind them. This screen question checks order statistics of uniforms, an unbiasedness argument, and practical trade-offs like merging sketches.

What the Interviewer Expects
  • Map hashed IDs to i.i.d. uniforms and note duplicates hash identically
  • Explain why the k-th smallest of D uniforms is Beta distributed
  • Show E[(k-1)/U_(k)] = D
  • Derive relative standard error about 1/sqrt(k-2)
  • Explain merge by union of sketches and compare with HyperLogLog
Key Topics to Cover
k-minimum values
order statistics
Beta distribution
sketching
cardinality estimation
How to Approach This
  1. Define your hypotheses (H0 and H1) clearly before performing any test.
  2. Calculate required sample size BEFORE running an experiment, using power analysis.
  3. Remember the Central Limit Theorem: sample means become approximately normal with large n.
  4. Watch for Simpson's paradox. Always segment data by key dimensions.
  5. Distinguish between statistical significance and practical significance.
Possible Follow-up Questions
  • How do you estimate the distinct count of the intersection of two videos' audiences?
  • Why does this estimator struggle for small intersections?
  • How would you choose k for a 1% target error?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Browse Statistics Questions
Sample Answer
Clarify
  • Stream of viewer IDs with repeats; true distinct count DD.
  • Hash hh maps IDs to (0,1)(0,1), behaving like i.i.d. uniforms across distinct IDs.
  • Keep only the kk smallest distinct hash values; memo...
Approach

Repeats of an ID give the same hash, so the set of hash values is DD i.i.d. U(0,1)U(0,1) draws. With DD points, the kk-th smallest U(k)∼Beta(k,D−k+1)U_{(k)} \sim \text{Beta}(k, D - k + 1) and E[U(k)]=k/(D+1)E[U_{(k)}] = k/(D+1). A...


Submit Your Answer
Markdown supported