#C9967. Jump Game: Can You Reach the End?
Jump Game: Can You Reach the End?
Jump Game: Can You Reach the End?
You are given an array of non-negative integers where each element represents the maximum jump length from that position. Starting at index 0, your goal is to reach the last index or beyond.
Formally, given an array \( A \) of length \( n \), you start at index 0. For each position \( i \), you can jump to any position \( j \) such that \( i < j \leq i + A[i] \). Determine whether it is possible to reach an index \( \geq n-1 \).
Input Format: The first line contains an integer \( T \) indicating the number of test cases. For each test case, the first line contains an integer \( n \) (the number of elements). The second line contains \( n \) space-separated non-negative integers representing the jump lengths.
Constraints: \(1 \leq T \leq 1000\), \(1 \leq n \leq 10^5\), and each array element is a non-negative integer.
inputFormat
The input begins with an integer \( T \) (number of test cases). Each test case consists of two lines. The first line contains an integer \( n \) (the size of the array). The second line contains \( n \) space-separated non-negative integers representing the maximum jump lengths at each index.
outputFormat
For each test case, output a single line containing either YES
if it is possible to reach or exceed the last index of the array, or NO
otherwise.
4
5
2 3 1 1 4
5
3 2 1 0 4
5
0 2 1 0 4
1
0
YES
NO
NO
YES
</p>