Starting at index 0, nums[i] is the maximum jump length from index i. Return the minimum number of jumps to reach the last index (it is always reachable).
Indices reachable with exactly k jumps form a contiguous window. Scan the current window, track the farthest index reachable from it, and when the window ends, take a jump: the next window ends at that farthest point.
1function jump(nums: number[]): number {2let jumps = 0, end = 0, far = 0;3for (let i = 0; i < nums.length - 1; i++) {4far = Math.max(far, i + nums[i]);5if (i === end) { jumps++; end = far; }6}7return jumps;8}
Window for 0 jumps is just index 0.
Space: play/pause · ←/→: step