#C7268. Minimum Jumps to Reach the End
Minimum Jumps to Reach the End
Minimum Jumps to Reach the End
In this problem, you are given a sequence of integers where each integer represents the maximum number of steps you can move forward from that position. Your task is to determine the minimum number of jumps required to reach the final position of the board. If it is impossible to reach the end, you should output (-1).
The problem can be formulated as follows: Given an array (A) of length (n), starting from index (0), find the minimum number of jumps needed to reach index (n-1). If reaching the end is not possible, return (-1).
inputFormat
The first line contains an integer (T) denoting the number of test cases. For each test case:
- The first line contains an integer \(n\) — the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the board.
outputFormat
For each test case, output a single line containing the minimum number of jumps required to reach the end or (-1) if it is impossible.## sample
3
5
2 3 1 1 4
5
1 0 0 1 1
5
3 2 1 0 4
2
-1
-1
</p>