1122. Jump Game I — Can Reach End

EasyDynamic Programming1D DPGreedy

Given an array nums where nums[i] is the maximum jump length from index i, determine whether you can reach the last index starting from index 0. Return true or false. The input is JSON {nums}.

Input: JSON {nums}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"nums":[2,3,1,1,4]}
Output: true
Explanation: Reach the end via index 1.
Example 2
Input: {"nums":[3,2,1,0,4]}
Output: false
Explanation: Stuck at the 0.
Example 3
Input: {"nums":[0]}
Output: true
Explanation: Already at the end.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →