Find shortest jumps in circular array
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates graph-traversal and modular arithmetic skills by requiring modeling a circular array as a state graph and determining reachability and minimum-distance jumps under wrap-around constraints.
Constraints
- 1 <= len(arr) <= 200000
- 0 <= arr[i] <= 10^9
- 0 <= start, target < len(arr)
Examples
Input: ([2, 1, 2, 3], 0, 3)
Expected Output: -1
Explanation: From index 0 you can only reach index 2, and from index 2 you can only return to index 0, so index 3 is unreachable.
Input: ([1, 1, 1, 1], 0, 2)
Expected Output: 2
Explanation: One shortest path is 0 -> 1 -> 2. Another is 0 -> 3 -> 2.
Hints
- Treat each index as a node in a graph, with up to two outgoing edges to the indices you can jump to.
- Since every jump has the same cost, a level-by-level traversal helps find the minimum number of jumps.