← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE interview with a DP problem that looked simple on the surface but had this weird constraint about prime numbers ending in 3. Not a round I felt great leaving.

Questions Asked (1)

Q1

You're given an integer array and start at index 0. At each step you can move 1 cell to the right, or jump forward by any prime number whose last digit is 3 (so 3, 13, 23, 43, and so on). You accumulate values at every cell you land on. What's the maximum sum you can collect by the time you reach the end?

Algorithms & Data Structures
Author's notes

The jump rule is what got me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a dynamic programming problem where dp[i] represents the maximum sum to reach index i. For each index, consider all valid moves (1 step right or prime jumps ending in 3) and take the maximum. Precompute the valid prime jumps up to the array length to optimize.

Pro tip: Clarify with the interviewer whether you can land on the same cell multiple times or if each cell can be collected only once; this affects whether the problem is a simple DP or requires tracking visited cells. Also, mention that you'd precompute primes ending in 3 using a sieve to avoid repeated checks.

1. Understand the problem and constraints

Confirm the rules: start at index 0, moves are +1 or +p where p is a prime ending in 3, and you collect the value at each landed cell. Ask about array size, value ranges, and whether cells can be revisited.

2. Define the DP state and recurrence

Let dp[i] be the maximum sum to reach index i. Initialize dp[0] = arr[0]. For each i from 1 to n-1, dp[i] = arr[i] + max(dp[i-1], max over valid primes p ≤ i of dp[i-p]).

3. Precompute valid prime jumps

Use the Sieve of Eratosthenes up to n to find all primes, then filter those whose last digit is 3. Store them in a list for quick access during DP.

4. Implement and optimize

Iterate through the array, and for each index, check all valid prime jumps. If the number of such primes is large, consider optimizing by grouping or using a sliding window, but typically O(n * number_of_primes) is acceptable.

5. Analyze complexity and edge cases

Time complexity: O(n * P) where P is the number of primes ending in 3 up to n; space O(n). Handle edge cases: n=1, no valid jumps, negative values (though problem implies positive? clarify).

Key Points to Mention

  • Dynamic programming approach with state dp[i] = max sum to reach index i.
  • Precomputation of primes ending in 3 using Sieve of Eratosthenes.
  • Recurrence relation: dp[i] = arr[i] + max(dp[i-1], max_{p} dp[i-p]).
  • Time and space complexity analysis.
  • Edge cases: single element, no valid prime jumps, negative numbers.
  • Clarify if cells can be revisited or if each cell's value is collected only once.

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