Skip to content

Start typing to search patterns, problems and pages.

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.

⏱ about 10 minutesNeeds: arraysTime O(n)

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
  1. Medium01

    Maximum Subarray

    Extend the running sum or restart it, keeping the best seen.

  2. Medium02

    Jump Game

    The one you just watched. Write it from memory.

UP NEXT · LESSON 15 OF 15IntervalsSort by start, then merge or split.