You start at index 0, and nums[i] is your maximum jump length from index i. Return true if you can reach the last index.
Walk from the end. Whenever index i can reach the current goal, i becomes the new goal. Success if the goal reaches 0.
1function canJump(nums: number[]): boolean {2let goal = nums.length - 1;3for (let i = nums.length - 2; i >= 0; i--) {4if (i + nums[i] >= goal) goal = i;5}6return goal === 0;7}
The goal starts at the last index.
Space: play/pause · ←/→: step