Jump Game III

Given an array of non-negative integers arr, you are initially positioned at index start of the array. When you are at index i, you can jump to either i + arr[i] or i - arr[i].

Return whether you can reach any index whose value is 0.

Notice that you cannot jump outside of the array at any time.

Example 1
Inputarr = [4,2,3,0,3,1,2], start = 5
Outputtrue
Starting from index 5, you can reach index 3 with value 0 via paths such as 5 -> 4 -> 1 -> 3 or 5 -> 6 -> 4 -> 1 -> 3.
Example 2
Inputarr = [4,2,3,0,3,1,2], start = 0
Outputtrue
Starting from index 0, one possible way to reach index 3 with value 0 is 0 -> 4 -> 1 -> 3.

Constraints

  • 1 <= arr.length <= 5 * 10^4
  • 0 <= arr[i] < arr.length
  • 0 <= start < arr.length

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate