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.
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
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;
}
}