← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Uber SWE interview with a graph traversal problem on a circular array. The problem looked deceptively simple but had a nasty edge case that I didn't catch until I was halfway through my solution.

Questions Asked (1)

Q1

Given a circular array, you can jump from index i exactly arr[i] steps left or right (with wraparound). Find the minimum number of jumps to get from a start index to a target index, or return -1 if it's unreachable.

Algorithms & Data Structures
Author's notes

My first instinct was BFS and that was right, but I spent too long second-guessing myself on the modulo wrapping for leftward jumps.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path on a graph where each index is a node and edges connect to (i ± arr[i]) mod n. Use BFS to find the minimum number of jumps from start to target, as BFS guarantees the shortest path in an unweighted graph. If BFS exhausts all reachable nodes without finding the target, return -1.

Pro tip: Clarify edge cases upfront: what if start equals target? (return 0) and what if arr[i] is 0? (no moves from that index). Also mention that BFS is optimal here because all edges have equal weight (1 jump).

1. Understand the problem and edge cases

Confirm the circular nature (wraparound using modulo), that jumps can be left or right, and handle edge cases like start == target (return 0) and arr[i] == 0 (no moves).

2. Model as a graph

Treat each index as a node. From index i, add directed edges to (i + arr[i]) % n and (i - arr[i] + n) % n. This forms an unweighted graph.

3. Apply BFS for shortest path

Use a queue to perform BFS from the start index, tracking visited nodes and the number of jumps (level). Stop when target is reached or queue is empty.

4. Return result and analyze complexity

If target is found, return the jump count; else return -1. Time complexity is O(n) since each node is visited at most once, and space is O(n) for the queue and visited set.

Key Points to Mention

  • Graph modeling: indices as nodes, jumps as edges
  • BFS guarantees shortest path in unweighted graphs
  • Modulo arithmetic for circular wraparound
  • Visited set to avoid cycles and redundant work
  • Time and space complexity: O(n) time, O(n) space
  • Edge cases: start == target, arr[i] == 0, unreachable target

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