Problem of the day
Input:
‘N’ = 3
‘ARR’ = [ 2, 1, 1 ]
The shortest way to reach index 2 is
Index 0 => Index 2
that requires only 1 jump.
The first line contains ‘T,’ denoting the number of test cases.
The first line of each test case contains ‘N’ denoting the size of the ‘ARR’.
The second line of each test case contains 'N' space-separated Integers denoting the ‘ARR’.
For each test case, Return the answer as described in the problem statement.
Output for each test case is printed on a separate line.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10000
0 <= ARR [ i ] <= N
Time Limit: 1 sec
2
5
2 3 1 1 4
4
1 1 1 1
Sample Output 1:
2
3
For the first test case:-
The optimal path is:
0 => 1 => 4
For the second test case:-
0 => 1 => 2 => 3
2
5
2 3 0 1 4
3
1 0 2
2
-1