Algorithms Playbook
← All problems
MediumGreedy →Similar to: Jump Game

Can you reach the last cell?

Problem

You start at index 0 of an array of non-negative integers. nums[i] is the maximum jump length from index i. Return whether you can reach the last index.

Examples

Input: [2, 3, 1, 1, 4]

Output: true

Input: [3, 2, 1, 0, 4]

Output: false

Every path ends stuck at the 0 at index 3.

Hints

    Try it first. Every hint reveals a bit more.

    Solution