Jump Game III - Problem
Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i].
Check if you can reach any index with value 0.
Notice that you cannot jump outside of the array at any time.
Input & Output
Example 1 — Basic Reachable Case
$
Input:
arr = [4,2,3,0,3,1,2], start = 5
›
Output:
true
💡 Note:
Start at index 5 (value 1). Can jump to index 6 (5+1) or index 4 (5-1). From index 4 (value 3), can jump to index 1 (4-3) or index 7 (out of bounds). From index 1, can reach index 3 which has value 0.
Example 2 — Unreachable Zero
$
Input:
arr = [4,2,3,0,3,1,2], start = 0
›
Output:
true
💡 Note:
Start at index 0 (value 4). Can jump to index 4 (0+4). From index 4 (value 3), can reach index 1 or 7. From index 1, can reach index 3 which has value 0.
Example 3 — No Zero Reachable
$
Input:
arr = [3,0,2,1,2], start = 2
›
Output:
false
💡 Note:
Start at index 2 (value 2). Can jump to index 0 (2-2) or index 4 (2+2). From these positions, cannot reach index 1 which contains the only zero.
Constraints
- 1 ≤ arr.length ≤ 5 × 104
- 0 ≤ arr[i] < arr.length
- 0 ≤ start < arr.length
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array with jump distances and starting position
2
Jump Rules
From index i, can jump to i+arr[i] or i-arr[i]
3
Goal
Find if any position with value 0 is reachable
Key Takeaway
🎯 Key Insight: Transform array jumping into graph traversal with cycle detection
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code