#K14771. Minimum Number of Jumps

    ID: 24209 Type: Default 1000ms 256MiB

Minimum Number of Jumps

Minimum Number of Jumps

You are given a series of platforms, each with a maximum jump power. Starting from the first platform (index 0), you need to determine the minimum number of jumps required to reach the last platform. If it is impossible to reach the end, output -1.

For each test case, the input consists of an integer N representing the number of platforms, followed by N space-separated integers where each integer (P[i]) indicates the maximum number of steps you can jump forward from the (i^{th}) platform.

Note: When there is only one platform, no jumps are needed.

inputFormat

The first line contains an integer T, the number of test cases. For each test case, the first line contains an integer N, the number of platforms. The second line contains N space-separated integers representing the maximum jump lengths from each platform.

outputFormat

For each test case, output the minimum number of jumps required to reach the last platform on a new line. If it is impossible to reach the end, output -1.## sample

3
5
3 3 1 0 2
4
2 1 0 3
3
1 1 1
2

-1 2

</p>