Tap here to switch tabs
Problem
Submissions

Problem: Jump Game IV

Try to solve the Jump Game IV problem.

Statement

Given an integer array arr, you initially start at the first index 00.

In a single step, from your current index i, you can jump to:

  • i + 11, provided that i + 1<1 < arr.length.

  • i - 11, provided that i - 1≥01 \geq 0.

  • Any index j such that arr[i] == arr[j] and i ≠\neq j.

Return the minimum number of jumps needed to reach the last index of the array.

Constraints:

  • 1≤1 \leq arr.length ≤5×104\leq 5 \times 10^4

  • −108≤-10^8 \leq arr[i] ≤108\leq 10^8

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Jump Game IV

Try to solve the Jump Game IV problem.

Statement

Given an integer array arr, you initially start at the first index 00.

In a single step, from your current index i, you can jump to:

  • i + 11, provided that i + 1<1 < arr.length.

  • i - 11, provided that i - 1≥01 \geq 0.

  • Any index j such that arr[i] == arr[j] and i ≠\neq j.

Return the minimum number of jumps needed to reach the last index of the array.

Constraints:

  • 1≤1 \leq arr.length ≤5×104\leq 5 \times 10^4

  • −108≤-10^8 \leq arr[i] ≤108\leq 10^8