68. Jump Game

MediumArrayArray

You are given an integer array nums where nums[i] represents the maximum jump length from index i. Return true if you can reach the last index starting from index 0, else false.

Input: An integer array nums of length n.

Output: true if last index is reachable, else false.

Examples

Example 1
Input: [2,3,1,1,4]
Output: true
Explanation: Jump 1 from index 0 to 1, then 3 jumps to the last index. Or jump 2 to index 2, 1 to 3, 1 to 4.
Example 2
Input: [3,2,1,0,4]
Output: false
Explanation: No matter what, you always reach index 3 where jump is 0. Can't proceed further.
Example 3
Input: [0]
Output: true
Explanation: Already at last index.

Constraints

Asked by

AdobeAmazonBloombergMicrosoftGoogleMeta
Solve this problem in the editor →