#K67837. Taco Jump Reachability
Taco Jump Reachability
Taco Jump Reachability
In this problem, you are given an integer ( n ) and an array of ( n ) non-negative integers where each element represents the maximum jump length at that position. Your task is to determine whether you can reach the last index starting from the first index. More formally, let the array be ( arr[0 \ldots n-1] ). Initially, you are at position 0. At each position ( i ), you can move to any position ( j ) such that ( i < j \le i + arr[i] ). If there exists a sequence of jumps that leads from the first index (0) to the last index (( n-1 )), print "YES"; otherwise, print "NO".
inputFormat
The input is given via standard input (stdin) and consists of two lines. The first line contains an integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated non-negative integers representing the array ( arr ).
outputFormat
Output via standard output (stdout) a single line containing either "YES" if it is possible to reach the last index, or "NO" otherwise.## sample
6
2 3 1 1 4
YES