Back to course home
0% completed
Jump Game III (medium)
Problem Statement
You are given an array of non-negative integers arr
and an initial position start
.
Starting at start
, you can jump either arr[start]
steps to the right
or arr[start]
steps to the left
.
Return true
if you can reach any index in the array that contains the value 0. Otherwise, return false
.
Note that you cannot jump outside the bounds of the array.
Examples
Example 1:
- Input: arr: [2, 2, 0, 3, 4], start: 1
- Output: true
- Justification: Starting from index 1, jump to index 3, then jump to index 0, and then jump to index 2, which contains 0.
Example 2:
- Input: arr: [4, 1, 2, 3, 1, 0], start: 4
- Output: true
- Justification: Starting from index 4, jump to index 5, which contains 0.
Example 3:
- Input: arr: [2, 3, 1, 1, 4], start: 0
- Output: false
- Justification: Starting from index 0, it is not possible to reach any index containing 0.
Constraints:
- 1 <= arr.length <= 5 * 10<sup>4</sup>
- 0 <= arr[i] < arr.length
- 0 <= start < arr.length
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
Mark as Completed
Table of Contents
Problem Statement
Examples
Try it yourself