← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE coding round with a dynamic programming problem that looked deceptively simple but had a weird prime number twist that slowed me down more than I expected.

Questions Asked (1)

Q1

Given an integer n, you start at step 0 and want to reach step n exactly. Each move lets you jump exactly 1 step, or any prime number of steps whose decimal representation ends in the digit 3 (e.g. 3, 13, 23, 43). Count the distinct jump sequences to reach step n, returning the result modulo 1,000,000,007. Assume n can be up to 100,000.

Algorithms & Data Structures
Author's notes

The DP structure itself wasn't the hard part, that clicked pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a dynamic programming problem where dp[i] = number of ways to reach step i, computed as dp[i] = dp[i-1] + sum(dp[i-p]) for all valid prime p ending in 3. Precompute all such primes up to n using a sieve, then iterate i from 1 to n, using modulo 1,000,000,007 to keep numbers manageable.

Pro tip: Mention that you can optimize memory to O(max_prime) by keeping a sliding window of recent dp values, and emphasize that the sieve is O(n log log n) while the DP is O(n * number_of_primes), which is efficient for n=100,000.

1. Understand the problem and define DP state

Clarify that we need to count distinct sequences of jumps, where each jump is either 1 or a prime ending in 3. Define dp[i] as the number of ways to reach step i exactly.

2. Identify valid jump lengths

Generate all primes up to n using the Sieve of Eratosthenes, then filter those whose decimal representation ends in 3 (i.e., p % 10 == 3).

3. Derive the recurrence relation

For each i from 1 to n, dp[i] = dp[i-1] + sum(dp[i-p]) for all valid primes p ≤ i. Use modulo 1,000,000,007 at each addition.

4. Implement and optimize

Iterate i from 1 to n, compute dp[i] using the recurrence. Optionally, use a sliding window or prefix sums to reduce memory, but O(n) space is acceptable for n=100,000.

5. Analyze complexity and edge cases

Time complexity: O(n log log n) for sieve + O(n * k) for DP, where k is the number of valid primes (≈ n / (10 log n)). Space: O(n). Handle n=0 (return 1) and ensure modulo operations prevent overflow.

Key Points to Mention

  • Dynamic programming with state dp[i] representing ways to reach step i.
  • Sieve of Eratosthenes to efficiently find all primes up to n.
  • Filtering primes that end with digit 3 (p % 10 == 3).
  • Modulo arithmetic to handle large counts (mod 1,000,000,007).
  • Time and space complexity analysis: O(n log log n) sieve, O(n * k) DP, O(n) space.
  • Edge cases: n=0 (1 way), n=1 (only jump 1), and ensuring no negative indices.

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