Estimating Daily Distinct Users From the Smallest Hash Value
Last updated: November 29, 2026
Quick Overview
You hash every user ID seen today to a uniform value in (0,1) and keep only the minimum. Show how to estimate the number of distinct users from it, why a single minimum is too noisy, and how keeping the k smallest fixes that.
0
0
0 solved
You hash every user ID seen today to a uniform value in (0,1) and keep only the minimum. Show how to estimate the number of distinct users from it, why a single minimum is too noisy, and how keeping the k smallest fixes that.
Approximate distinct counting underpins Google analytics systems and BigQuery's APPROX_COUNT_DISTINCT. This question checks whether a candidate can derive the estimator from order statistics, quantify its variance, and explain the k-minimum-values sketch.
What the Interviewer Expects
- Explain that duplicates hash to the same value, so only distinct count n matters
- Derive E[min] = 1/(n+1)
- Show 1/min - 1 has huge variance (infinite mean)
- Use the k-th smallest value with estimator (k-1)/U_(k)
- Relative error about 1/sqrt(k)
Key Topics to Cover
How to Approach This
- Define your hypotheses (H0 and H1) clearly before performing any test.
- Calculate required sample size BEFORE running an experiment, using power analysis.
- Remember the Central Limit Theorem: sample means become approximately normal with large n.
- Watch for Simpson's paradox. Always segment data by key dimensions.
- Distinguish between statistical significance and practical significance.
Possible Follow-up Questions
- How does HyperLogLog improve memory per unit of accuracy compared with KMV?
- How do you merge sketches from two days or two datacenters?
- How would you estimate the size of an intersection of two user sets?
- What happens if the hash function is not close to uniform?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Browse Statistics QuestionsSample Answer
Clarify
A uniform hash maps each distinct user to an independent Uniform(0,1) value; repeated events from the same user give the same hash. With distinct users, the minimum is the minimum of ...
Approach
Use the distribution of order statistics of uniforms. The -th smallest of uniforms is Beta(). Invert its expectation, then check the variance....