← Back to Leo Academy Masterclass

Problem #55: Jump Game

Medium Array & String

Intuition & Strategy Breakdown

Greedily track the maximum index reachable so far. Iterate through the array; if current index exceeds maximum reachable index, return false. Otherwise update max reach.

Python Solution

class Solution:
    def canJump(self, nums: list[int]) -> bool:
        goal = len(nums) - 1
        for i in range(len(nums) - 1, -1, -1):
            if i + nums[i] >= goal:
                goal = i
        return goal == 0

Java Solution

class Solution {
    public boolean canJump(int[] nums) {
        int goal = nums.length - 1;
        for (int i = nums.length - 1; i >= 0; i--) {
            if (i + nums[i] >= goal) {
                goal = i;
            }
        }
        return goal == 0;
    }
}
Watch Interactive Video on Leo Academy Main App