#C8757. Jump Game: Can You Reach the End?
Jump Game: Can You Reach the End?
Jump Game: Can You Reach the End?
Given an array of integers where each element represents the maximum jump length from that position, determine if you can reach the last index starting from the first index. This classical problem, often known as the Jump Game, challenges you to use a greedy approach to track the farthest position reachable as you progress through the array.
Formally, you are given an array \( jumps \) of \( n \) integers. Starting at index 0, each element \( jumps[i] \) indicates the maximum jump length from that position. Some jumps may even be negative, representing backward moves. Your task is to decide whether you can reach the last index (index \( n-1 \)).
Input Format: The first line contains an integer \( n \), representing the number of elements in the array. The second line contains \( n \) space-separated integers, which are the elements of the array.
Output Format: Print True
if the last index is reachable, otherwise print False
.
inputFormat
The first line contains an integer ( n ) (the number of elements in the array). The second line contains ( n ) space-separated integers representing the jump lengths.
outputFormat
Print "True" if the last index can be reached from the first index, otherwise print "False".## sample
5
2 3 1 1 4
True
</p>