


The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains a single integer ‘N’ denoting the size of the ‘arr’ array.
The next line contains ‘N’ space-separated integers denoting the values of elements of the ‘arr’ array.
For each test case, print a single line containing the number of starting indices, from where Ninja can reach the end by following the required jump conditions.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 5000
0 <= arr[i] < 10 ^ 6
Where ‘T’ is the number of test cases, ‘N’ is the size of an array, and ‘arr[i]’ represents the elements of the array.
Time Limit: 1 sec
The idea here is to use the brute force approach and to travel the whole array for each index we will check if we can reach the last index of the array by following the given conditions.
The idea here is to use the stack as we know that we want to find out the current index and the jump type whether we are taking an even jump or an odd jump. For each index, there are two options either we can make the jump or not. So if we knew these jumps, we can be able to find out the answer in a single traversal.
The idea here is to use the map as a map to help in reducing the time complexity as now we think of starting from right to left and try to check by using the property of map lower_bound and upper_bound, so basically there are two functions which can be called using a map and they can tell whether the larger element is present than the element we pass in this function or smaller element is present.