← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE interview with a classic dynamic programming problem. Nothing too surprising but you need to actually know your interval DP or you'll flounder.

Questions Asked (1)

Q1

You're playing a number guessing game where a number is chosen from 1 to n. Each wrong guess costs you the amount you guessed, and you're told whether the answer is higher or lower. What's the minimum amount of money you need to guarantee a win no matter what number was picked?

Algorithms & Data Structures
Author's notes

This is interval DP once you see it, but if you don't immediately recognize the pattern you can waste a lot of time trying to think about it as a greedy problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a dynamic programming problem where you need to minimize the maximum cost across all possible target numbers. Define dp[i][j] as the minimum cost to guarantee a win when the number is in range [i, j], and derive the recurrence by considering each possible guess k and taking the worst-case cost. Optimize the O(n^3) DP to O(n^2) using monotonicity or Knuth's optimization if needed.

Pro tip: After presenting the DP, mention that the optimal first guess is often around n/√2 or derived from the recurrence, and that the problem is equivalent to finding the optimal binary search tree with weights equal to the guessed numbers. This shows depth and connects to classic algorithms.

1. Clarify the problem

Confirm that the cost is the sum of all wrong guesses, and that you need the minimum total cost that guarantees a win regardless of the chosen number. Ask if n is given and if there are constraints on n.

2. Define the DP state

Let dp[i][j] be the minimum cost to guarantee a win for a number in the range [i, j]. The base case is dp[i][i] = 0 (no cost if only one number, you guess it correctly).

3. Derive the recurrence

For each possible guess k in [i, j], the cost is k + max(dp[i][k-1], dp[k+1][j]). The answer for range [i, j] is the minimum over k of this expression. Explain why we take the max: because the adversary chooses the direction that maximizes cost.

4. Compute and optimize

Naively, the DP takes O(n^3) time. Mention that it can be optimized to O(n^2) using Knuth's optimization or by observing monotonicity of the optimal guess. For small n, O(n^3) is acceptable.

5. Return the answer

The final answer is dp[1][n]. Optionally, discuss how to reconstruct the optimal guessing strategy.

Key Points to Mention

  • Dynamic programming state definition and base cases
  • Recurrence relation: dp[i][j] = min_{k} (k + max(dp[i][k-1], dp[k+1][j]))
  • Worst-case analysis: adversary chooses the direction that maximizes cost
  • Time complexity: O(n^3) naive, O(n^2) with optimization
  • Connection to optimal binary search tree or minimax problems
  • Edge cases: n=1, n=2, and large n

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