← Reddit Interview Insights

Reddit·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Reddit data scientist interview with a probability question that sounds like a stats class warmup but has enough moving parts to trip you up if you're not careful. One question, math-heavy, with an optional coding component.

Questions Asked (1)

Q1

You roll two fair dice independently: die A has m faces and die B has n faces, each labeled starting from 1. Derive a closed-form expression for the probability that A lands higher than B, as a function of m and n. Bonus: write a Python function to compute it.

Algorithms & Data StructuresProduct Analytics & Metrics
Author's notes

I knew the setup immediately but fumbled the algebra for longer than I'd like to admit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the sample space of m*n equally likely outcomes. Count the number of outcomes where die A > die B by summing over possible values of die B or using symmetry and the total number of outcomes. Derive a closed-form expression, then verify with small cases and provide a Python implementation.

Pro tip: Mention that the formula can be expressed as (m(m+1)/2 - m + something) but actually the clean result is (m(m+1)/2 - m + n(n-1)/2) / (m*n) — wait, better to derive properly. A good tip: use symmetry to relate P(A>B) to P(B>A) and P(A=B), which simplifies counting. Also, always test edge cases like m=1 or n=1.

1. Define the sample space and event

Clearly state that there are m*n equally likely outcomes (i, j) where i is from die A and j from die B. The event of interest is i > j.

2. Count favorable outcomes

For each value j on die B, count the number of i on die A such that i > j. Sum over j=1 to n. This gives sum_{j=1}^n (m - j) for j < m, but careful when j >= m. Alternatively, use the identity: number of pairs with i > j = total pairs - pairs with i <= j.

3. Derive closed-form expression

Compute the sum: sum_{j=1}^n max(0, m - j). This equals sum_{j=1}^{min(n,m-1)} (m - j). Evaluate the sum to get a piecewise formula or a single expression using min. Then divide by m*n.

4. Simplify and verify

Simplify the expression, e.g., if m <= n, the sum is m(m-1)/2; if m > n, it's n*m - n(n+1)/2. Combine using min. Check with small values like m=2, n=2 (should be 1/4) and m=3, n=2 (should be 3/6=1/2).

5. Provide Python implementation

Write a function that computes the probability using the derived formula, handling edge cases. Optionally, include a simulation to validate.

Key Points to Mention

  • Equally likely outcomes and uniform distribution over m*n pairs.
  • Counting technique: sum over one die's outcomes.
  • Use of min/max to handle cases where m and n differ.
  • Symmetry: P(A>B) + P(B>A) + P(A=B) = 1, and P(A=B) = min(m,n)/(m*n).
  • Closed-form expression: (m(m-1)/2 - max(0, m-n)(m-n-1)/2) / (m*n) or equivalent.
  • Python implementation with integer arithmetic to avoid floating point issues, and testing edge cases.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.