Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Fewest Leaps

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Treat each jump as one breadth layer: The Fewest Leaps.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Greedy jump frontier matches the clues
  2. 2Keep this true after every move: currentEnd is the farthest index reachable with `jumps` moves and farthest is the next layer boundary
  3. 3Reach the result within O(n)

Rules and pressure

  • Target cost: O(n)
  • State rule: currentEnd is the farthest index reachable with `jumps` moves and farthest is the next layer boundary
Lesson 1 of 3

Live algorithm trace

Greedy jump frontier

Complete execution
1 of 6

Before jumping, only index 0 belongs to the current launch layer.

1jumps = 0; currentEnd = 0
2farthest = max(farthest, i + nums[i])
3when i reaches currentEnd
4jumps += 1
5currentEnd = farthest
6stop once the end is covered
jumps = 0currentEnd = 0farthest = 0
Truth to preserve / Cost target
Truth to preserve

currentEnd is the farthest index reachable with `jumps` moves and farthest is the next layer boundary

Cost target

O(n)

All indices reachable with the current jump form one range. Scan that range for the farthest next reach, then commit one jump only when the current range ends.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead