Greedy
Cross a stream on stepping stones without ever planning the route. From each stone, only note the farthest stone you could land on. If the next stone sits past that mark, the crossing is impossible, and you knew without retracing a step.
2 · Watch
No sound? Captions are on by default.
3 · Now you drive
Keys:←→ stepSpace playR reset
Jump Game
or try
1–10 jump lengths from 0 to 5, separated by spaces.You stand on stone 0. So far you can reach stone 0.Step 1 of 7. 5 stones, jumps 2, 3, 1, 1, 4. Standing on stone 0. Farthest reachable stone 0.
Step 1 of 7
solution.ts▶ marks the line running now
function canJump(nums: number[]): boolean {
let reach = 0;
for (let i = 0; i < nums.length; i++) {
if (i > reach) return false;
reach = Math.max(reach, i + nums[i]);
}
return true;
}
4 · Your turn
0 of 2 problems solved
- Medium01
Maximum Subarray
Extend the running sum or restart it, keeping the best seen.
- Medium02
Jump Game
The one you just watched. Write it from memory.