


The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains a positive integer N, which represents the number of shops.
The next line contains 'N' single space-separated positive integers representing a constant given for each shop.
For each test case, print the minimum number of jumps or -1, if it is impossible to reach the last shop.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5 * 10^4
0 <= Arr[i] <= N
Where T is the number of test cases, N is the size of the array and Arr[i] is the ith element in the array.
We will recursively find the minimum number of jumps.
Let’s say we have a recursive function ‘minimumJumpsHelper’ which will return the minimum number of jumps to reach the last shop.
In the previous approach, we are recalculating the answer to reach the last shop from a shop. We can optimise it by storing the answer for the amount which we have calculated.
For example, if the given array is {2, 1, 3, 2, 4}:
We are recalculating the answer for shops {2, 3}.
So since there are overlapping solutions, we can store the solution which we have calculated. For this, we will make an array DP to store the answer.
DP[i] denotes the minimum number of jumps needed to reach the last shop from the ith shop.
Algorithm:
Make an array DP of size N to store the answer.
DP[i] denotes the minimum number of jumps needed to reach the last shop from the ith shop.
In this approach, we will calculate the farthest shop we can reach from shop 0 with x number of jumps.
For example, if the given array is {2, 3, 1, 2, 1} :
For x=1, we can reach shop 2 (shop 0 -> shop2).
For x=2, we can reach shop 4 (shop 0 -> shop1 -> shop 4)
Hence, we require a minimum two jumps to reach the last shop.