← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Uber coding round for a software engineer role. One dynamic programming problem that looked straightforward but had a weird constraint on the jump sizes that slowed me down.

Questions Asked (1)

Q1

Given a zero-indexed integer array, you can move forward either 1 step or x steps where x is a prime number ending in 3 (like 3, 13, 23, 43...). Each cell has a value, positive or negative. Find the maximum sum you can accumulate by the time you reach the last cell.

Algorithms & Data Structures
Author's notes

The DP part clicked pretty fast, but I wasted a good few minutes just staring at the prime constraint.

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 previous indices from which you can jump to i (either 1 step back or x steps back where x is a prime ending in 3), and take the maximum dp value plus the current cell's value. Precompute all primes ending in 3 up to the array length to efficiently check valid jumps.

Pro tip: Mention that you can optimize space by only keeping track of the last x steps needed, but since x can be up to n, a full dp array is often simpler and still O(n * number of primes) time. Also, clarify edge cases like negative values and unreachable cells.

1. Clarify problem constraints and edge cases

Ask about array size, possible values, and whether the last cell must be reached exactly. Confirm that you can only move forward and that x is a prime ending in 3.

2. Define DP state and recurrence

Let dp[i] be the maximum sum to reach index i. Initialize dp[0] = arr[0]. For i > 0, dp[i] = arr[i] + max(dp[i-1], max over valid x of dp[i-x] if i-x >= 0).

3. Precompute valid primes ending in 3

Generate all primes up to n that end with digit 3 using sieve or trial division. Store them in a list for quick access during DP transitions.

4. Iterate and compute DP

Loop i from 1 to n-1, compute dp[i] using the recurrence, handling cases where no valid jump exists (set dp[i] to -infinity). Finally, return dp[n-1].

5. Analyze complexity and potential optimizations

Time complexity is O(n * P) where P is the number of primes ending in 3 up to n. Space is O(n). Discuss possible optimizations like using a sliding window or segment tree if needed.

Key Points to Mention

  • Dynamic programming approach with state definition and recurrence relation
  • Precomputation of primes ending in 3 using sieve of Eratosthenes
  • Handling negative values and unreachable states (use -infinity)
  • Time and space complexity analysis
  • Edge cases: single element array, no valid path, large n
  • Potential optimizations: space reduction, using prefix maximums for prime jumps

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