The Jump Game III interview question is a reachability problem. You are given an array of non-negative integers and a starting index. From any index i, you can jump to i + arr[i] or i - arr[i], provided the new index is within the array bounds. Your goal is to determine if you can ever reach an index where the value is 0.
Companies like Goldman Sachs and Pinterest ask the Jump Game III coding problem to test a candidate's familiarity with Graph Traversal. Even though the input is an array, the jumps create a directed graph. It evaluation your ability to use BFS or DFS and manage a "visited" state to avoid infinite loops.
This problem follows the Graph Traversal (BFS or DFS) pattern.
start index into a stack (DFS) or queue (BFS).curr.arr[curr] == 0, return true.curr + arr[curr] and curr - arr[curr].false.arr = [4, 2, 3, 0, 3, 1, 2], start = 5
nextIndex < 0 or nextIndex >= arr.length.Whenever you see "from position X you can go to Y or Z," think BFS/DFS. If the edge weights are all 1 (or irrelevant), BFS is usually preferred for finding reachability or shortest paths in a Graph interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| The Maze | Medium | Solve | |
| Shortest Bridge | Medium | Solve | |
| Delete Tree Nodes | Medium | Solve | |
| Pacific Atlantic Water Flow | Medium | Solve | |
| Coloring A Border | Medium | Solve |