← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber coding round with a dynamic programming problem that looks straightforward until you actually think about what jumps are valid. The prime-ending-in-3 constraint is the kind of thing that trips you up if you don't slow down and enumerate your options first.

Questions Asked (1)

Q1

You have an integer array and start at index 0. At each position you can jump forward either 1 step or X steps, where X is a prime number whose last digit is 3 (so 3, 13, 23, 43, and so on). Each cell holds a value that can be positive or negative. Find the maximum sum you can accumulate by the time you reach the last index.

Algorithms & Data Structures
Author's notes

My first instinct was just standard DP, which is right, but I fumbled the setup because I didn't precompute the valid primes ending in 3 before writing the recurrence.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a dynamic programming problem where dp[i] represents the maximum sum to reach index i. Precompute all valid jump lengths (primes ending in 3) up to n, then for each index, consider all possible previous positions from which you can jump to it, and take the maximum. Return dp[n-1].

Pro tip: Clarify with the interviewer whether you can overshoot the last index or must land exactly on it, as this affects the DP transitions. Also, mention that you can optimize by only iterating over valid jump lengths rather than all indices, reducing time complexity.

1. Understand the problem and constraints

Restate the problem to ensure clarity: you start at index 0, can jump 1 or a prime ending in 3, and want to maximize the sum of visited cells including start and end. Ask about edge cases like negative values, array size, and whether jumps must land exactly on the last index.

2. Precompute valid jump lengths

Generate all prime numbers ending in 3 up to n-1 (the maximum possible jump length). Use a sieve or simple primality check, and store them in a list for efficient lookup.

3. Define DP state and transitions

Let dp[i] be the maximum sum to reach index i. Initialize dp[0] = arr[0] and others to -infinity. For each i from 1 to n-1, dp[i] = arr[i] + max(dp[i-1], max over valid jumps j where i-j is a valid jump length of dp[i-j]).

4. Handle unreachable states and return result

If dp[i] remains -infinity, it means index i is unreachable. After filling the DP table, return dp[n-1] if reachable, else indicate no valid path (or return -infinity).

5. Analyze complexity and optimize if needed

Time complexity is O(n * k) where k is the number of valid jump lengths (about n / log n). Space complexity is O(n). Mention that you can optimize space to O(max jump length) if only the last few states are needed, but O(n) is fine.

Key Points to Mention

  • Dynamic programming approach with state dp[i] = max sum to reach index i
  • Precomputation of valid jump lengths (primes ending in 3) using sieve or trial division
  • Transition: dp[i] = arr[i] + max(dp[i-1], dp[i-j] for valid jumps j)
  • Handling negative values: DP naturally handles them by taking maximum
  • Edge cases: unreachable last index, array of size 1, negative sums
  • Time and space complexity analysis: O(n * number of valid jumps) time, O(n) space

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