Class Solution

java.lang.Object
g1301_1400.s1306_jump_game_iii.Solution

public class Solution extends Object
1306 - Jump Game III.<p>Medium</p> <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach to <strong>any</strong> index with value 0.</p> <p>Notice that you can not jump outside of the array at any time.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> arr = [4,2,3,0,3,1,2], start = 5</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>All possible ways to reach at index 3 with value 0 are:</p> <p>index 5 -> index 4 -> index 1 -> index 3</p> <p>index 5 -> index 6 -> index 4 -> index 1 -> index 3</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> arr = [4,2,3,0,3,1,2], start = 0</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>One possible way to reach at index 3 with value 0 is:</p> <p>index 0 -> index 4 -> index 1 -> index 3</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> arr = [3,0,2,1,2], start = 2</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> There is no way to reach at index 1 with value 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= arr.length <= 5 * 10<sup>4</sup></code></li> <li><code>0 <= arr[i] < arr.length</code></li> <li><code>0 <= start < arr.length</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • canReach

      public boolean canReach(int[] arr, int start)