Problem · Array

Jump Game IV

Learn this problem
HardZomato / EternalONSITE INTERVIEW

Problem statement

Given an integer array arr, start at index 0. From index i, one jump may move to i - 1, i + 1, or any index j such that arr[i] == arr[j].

Return the minimum number of jumps needed to reach the last index. Indices outside the array are not valid destinations.

Function

minJumps(arr: int[]) → int

Examples

Example 1

arr = [100,-23,-23,404,100,23,23,23,3,404]return = 3

One shortest route is index 0 -> 4 -> 3 -> 9.

Example 2

arr = [7]return = 0

More Zomato / Eternal problems

drafts saved locally
public int minJumps(int[] arr) {
  // write your code here
}
arr[100,-23,-23,404,100,23,23,23,3,404]
expected3
checking account