Skip to content

Practice Jump Game IV

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1345
LeetCode Problem

Jump Game IV

Problem Statement

Start at index 0 of arr. One jump may move to an in-bounds adjacent index, i - 1 or i + 1, or to a different index j whose value equals arr[i]. Return the minimum jumps needed to reach the last index.

Source: Jump Game IV on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
arr = [100,-23,-23,404,100,23,23,23,3,404]
Output
3

# Example 2

Input
arr = [7]
Output
0

# Example 3

Input
arr = [7,6,9,6,9,6,9,7]
Output
1

Constraints

1 <= arr.length <= 5 * 10^4
-10^8 <= arr[i] <= 10^8

Related LeetCode Problems

Practice more problems similar to Jump Game IV.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.