← Google Interview Insights

Google·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
May 2026

Summary

Google SWE online assessment with a probability/dynamic programming problem that looks approachable until you actually think about it. The problem is well-defined but the edge cases are sneaky.

Questions Asked (1)

Q1

You start at position 0 on an infinite 1D integer grid. Each step you roll a K-sided die (values 1 through K, uniform) and move forward by that amount. Given a target interval [mn, mx], you win if you land anywhere inside it, and lose if you overshoot past mx without ever entering it. Compute the probability of winning.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Took me a while to even convince myself the recursion was right.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the process as a Markov chain or dynamic programming over positions, where the probability of winning from position i is the average of the probabilities from i+1 to i+K. Define base cases: probability 1 if i is in [mn, mx], and 0 if i > mx. Then compute the probabilities backwards from mx down to 0, using a sliding window to optimize the recurrence.

Pro tip: Mention that the recurrence can be computed in O(mx) time with a sliding window sum, and note that if K is large relative to the interval, the probability approaches 1/(average step) times interval length, but exact DP is needed for correctness.

1. Define the state and recurrence

Let P(i) be the probability of winning starting from position i. For i in [mn, mx], P(i)=1; for i > mx, P(i)=0. For i < mn, P(i) = (1/K) * sum_{d=1 to K} P(i+d).

2. Identify base cases and boundaries

Set P(i)=1 for i in [mn, mx] and P(i)=0 for i > mx. Note that positions beyond mx are losing, and positions inside the interval are immediate wins.

3. Compute probabilities backwards

Iterate i from mx-1 down to 0, computing P(i) using the recurrence. Use a sliding window sum of the next K probabilities to achieve O(mx) time.

4. Optimize with sliding window

Maintain a running sum of P(i+1) to P(i+K). When moving to i-1, subtract P(i+K) and add P(i) to update the window in O(1) per step.

5. Return the result and discuss complexity

The answer is P(0). Time complexity is O(mx) and space O(mx) (or O(K) with optimization). Discuss potential numerical issues and edge cases.

Key Points to Mention

  • Dynamic programming recurrence: P(i) = average of P(i+1) to P(i+K)
  • Base cases: P(i)=1 for i in [mn, mx], P(i)=0 for i > mx
  • Sliding window optimization to reduce time from O(K*mx) to O(mx)
  • Edge cases: mn=0 (immediate win), K=1 (deterministic), mx < 0 (impossible)
  • Space optimization: only need to keep last K probabilities
  • Numerical stability: probabilities can be very small, consider using logarithms or high precision if needed

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