↻one more pass.
Greedy · Medium

Jump Game: the idea to remember.

Each array value is a maximum forward jump length. Decide whether the final index is reachable.

Solve on LeetCode ↗

The core insight

Scan reachable indices and extend the furthest reach. Fail if the next index lies beyond that frontier.

Why it works

All positions up to the frontier are reachable because a jump may use any length up to its maximum. An index beyond it cannot be reached by any earlier choice.

The mistake to avoid

A zero matters only if no earlier jump can cross it. You need not land on every index.

Time: O(n)Space: O(1)

Commented Java solution

Use java.util.* imports and a surrounding solution class. Tree snippets assume the standard TreeNode definition; linked lists use ListNode and Clone Graph uses a Node with val and neighbors; Copy Random List uses Node with val, next and random. Read the input assumptions above.

boolean canJump(int[] nums) {
    int reach = 0;
    for (int i = 0; i < nums.length; i++) {
        if (i > reach) return false;
        reach = Math.max(reach, i + nums[i]);
        if (reach >= nums.length - 1) return true;
    }
    return true;
}

Make the next connection

Independent revision notes with credited Java references. Not affiliated with LeetCode or the source sheets.