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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

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
implicit graph
BFS
reachability
array
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: arr of non-negative ints, start index.
  • Moves: i + arr[i] and i - 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...


Submit Your Answer
Markdown supported