Reach a Zero-Valued Index by Jumping Left or Right
Last updated: November 29, 2026
Quick Overview
Given an array of non-negative integers and a start index, from index i you may jump to i + arr[i] or i - arr[i] if it stays in bounds. Return True if you can reach any index whose value is 0.
0
0
0 solved
Given an array of non-negative integers and a start index, from index i you may jump to i + arr[i] or i - arr[i] if it stays in bounds. Return True if you can reach any index whose value is 0.
An Online Assessment style question where the graph is implicit: indices are nodes and the two jumps are edges. Google interviewers like it because candidates who only think of arrays as DP tables miss that it is a reachability search.
What the Interviewer Expects
- Model indices as nodes with up to two outgoing edges
- Use BFS or DFS with a visited array
- Stop as soon as a zero is found
- Explain why it terminates despite cycles
- State O(n) time and space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the minimum number of jumps to reach a zero.
- What if you can also jump to any index holding the same value?
- What if each jump has a cost equal to the distance travelled?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
arrof non-negative ints,startindex. - Moves:
i + arr[i]andi - arr[i]when in[0, n). - Output: whether any index with value 0 is reachable....
High-Level Design
Treat each index as a node with at most two edges. Jumps can loop (for example 2 to 4 and back), so a visited array is required. Once an index is visited, revisiting it cannot discover anything new, w...