#C1336. Jump Game
Jump Game
Jump Game
You are given an array of non-negative integers nums where each element represents your maximum jump length at that position. Your task is to determine if you can reach the last index starting from the first index.
More formally, if you are at index i, you can jump to any index j such that \[ i+1 \le j \le i+nums[i] \] Determine whether it is possible to reach the last index of the array.
Example:
- Input: nums = [2, 3, 1, 1, 4]
- Output: True
- Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer n representing the number of elements in the array.
- The second line contains n space-separated non-negative integers representing the array nums.
outputFormat
Output a single line to standard output (stdout) containing either True
or False
(without quotes) indicating whether it is possible to reach the last index.
5
2 3 1 1 4
True
</p>