Hi👋SpeedAlgo • Deliberate Practice & Cognitive Ergonomics for Software Engineers

An interactive algorithm mastery and technical interview preparation platform published by Hi👋WebEnterprise. Built for senior and staff software engineers preparing for rigorous coding screens at top tech companies (FAANG/MAMAA).

12 Core Algorithmic Patterns & 168 Practice Problems

  • 1. Two Pointers (9 Paradigms, 32 Problems): Converging pointers, sorted pair sums, container with most water, trapping rain water, 3Sum, plus the Sliding Window and Fast & Slow Pointers paradigms (Floyd cycle detection, monotonic window invariants, longest substrings, minimum window).
  • 2. Binary Search (8 Paradigms, 12 Problems): Monotonic predicate partitioning, boundary searching, rotated arrays, median of two sorted arrays, matrix median on value range.
  • 3. Bit Manipulation (5 Paradigms, 8 Problems): Bitmasking, XOR tricks, counting set bits, subset enumeration via bitmasks.
  • 4. Math & Geometry (5 Paradigms, 10 Problems): Sieve of Eratosthenes, integer/roman conversions, modular arithmetic, geometric simulation.
  • 5. Tree/Graph Depth-First Search (8 Paradigms, 17 Problems): Path sums, lowest common ancestor, tree diameter, subtree serialization, validating BSTs.
  • 6. Tree/Graph Breadth-First Search (4 Paradigms, 11 Problems): Level-order traversals, shortest path, rotting oranges, word ladders.
  • 7. Graphs (6 Paradigms, 14 Problems): Topological sort, cycle detection, Dijkstra, bipartite validation, network delay.
  • 8. Backtracking (5 Paradigms, 13 Problems): Subsets, permutations, combinations, constraint satisfaction, pruning, N-Queens.
  • 9. Dynamic Programming (7 Paradigms, 14 Problems): Memoization vs tabulation, knapsack, coin change, edit distance, longest common subsequence.
  • 10. Heap / Priority Queue (8 Paradigms, 10 Problems): Running medians, top-k elements, interval scheduling, IPO, k-way merges.
  • 11. Advanced Data Structures (5 Paradigms, 13 Problems): Trie, Union-Find, LRU Cache, LFU Cache, Monotonic Stacks.
  • 12. Intervals & Stack / Miscellaneous (7 Paradigms, 14 Problems): Merge intervals, daily temperatures, largest rectangle in histogram, trapping rain water via stack.

4-Stage Deliberate Practice Framework

  1. Stage 1 (Compare & Learn): Multi-language Rosetta Stone contrasting abstract invariants with concrete solutions across Python, C#, Java, TypeScript, C++, Go, and Rust.
  2. Stage 2 (Active Recall): Reconstruct algorithmic template invariants from memory with real-time feedback before looking at solutions.
  3. Stage 3 (Senior SWE AI Mock Coach): Simulated senior mock interview evaluating Big-O space/time tradeoffs, edge cases, and code reviews in Monaco Editor.
  4. Stage 4 (Solve on Your Own): Timed sandbox challenges verified against automated test suites in Python, C#, Java, and TypeScript.

Equipped with SM-2 Spaced Repetition Review Hub, Studio Cockpit workspace layout, and interactive study notes.

Pricing, Access & Commercial Terms

  • Core Curriculum: 100% Free. No credit card required.
  • Compute Coins: 40 free coins upon signup, +20 daily login bonus, +25 referral bonus.
  • 24-Hour AI Coaching Pass: 5 compute coins unlocks unlimited senior SWE AI coaching for a full 24 hours.
  • BYOK (Bring Your Own Key): Completely free unlimited AI coaching if using your own Gemini/OpenAI API key.
  • Refund & Subscription Policy: No recurring charges, no subscription traps, and no paid paywalls. Free tier provides full learning path.
  • Platform Operator: Hi👋WebEnterprise Inc. Support & policies at hispeedalgo.com.
Skip to main content
Hi👋SpeedAlgo

Invariant-First Algorithmic Mastery

180Items
Theory Context•Miscellaneous & Sweeps
MediumLC 55

Jump Game (LeetCode 55)

You will see how one number, the furthest index any jump can reach, replaces a search over every path.

Target Frequency:AmazonGoogleMicrosoft

You get an integer array nums and begin on index 0. The value nums[i] is the longest jump you may make from index i: from there you can move forward by any whole number of steps from 1 up to nums[i], and a value of 0 means you cannot move on from that index.

Return true if some sequence of jumps lands you on the last index, and false if every sequence gets stuck before it.

Worked Examples

Example 1
Input:nums = [2,3,1,1,4]
Output:true
2031121344startjump 1jump 2
Explanation: Index 1 is one step away, and its value `3` carries you straight to index 4, the last index. Other routes work too; one is enough.
Example 2
Input:nums = [3,2,1,0,4]
Output:false
3021120344stuckout of reach
Explanation: Indices 0, 1 and 2 can each get as far as index 3 and no further (`0 + 3`, `1 + 2`, `2 + 1`), and index 3 holds `0`, so no jump ever passes it. Index 4 stays out of reach.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 104

  • 0 <= nums[i] <= 105

Deep-Dive & Conceptual Insights

Why It Works & Core Invariant

You never need the path, only how far any path can get: the reachable indices always form one block 0..reach, so one number and one pass decide the answer.

Real-World Scenario & Production Applications

Any chain of forward hops with a limited range per hop: relay stations along a pipeline, charging stops for a drone, stepping stones on a path. Whether the end can be reached never needs the full route, only the furthest point any route could reach so far, so one running number answers it in a single pass.

Step-by-Step Execution Trace Table

Example 2, nums = [3,2,1,0,4] (the trap case):

inums[i]Check i > reachreach = max(reach, i + nums[i])What it means
030 > 0: nomax(0, 0 + 3) = 3Indices 0 to 3 can be landed on
121 > 3: nomax(3, 1 + 2) = 3No further than before
212 > 3: nomax(3, 2 + 1) = 3No further than before
303 > 3: nomax(3, 3 + 0) = 3Index 3 can't move on
444 > 3: yes(not reached)No jump lands on index 4: return False
Scroll horizontally to see all columns, or expand to full screen
Core Invariant Specification & Code Shape
Archetype Code Shape
Python
1You never need the path, only how far any path can get: keep `reach`, the furthest index a run of jumps can land on so far.
2Every index from `0` to `reach` can be landed on (a jump may be shorter than `nums[i]`), so extend it with `reach = max(reach, i + nums[i])`: the larger reach keeps every option.
3Start `reach = 0`, loop `for i in range(len(nums))` once, and `return True` after the loop.
4The trap: check `if i > reach: return False` before reading `nums[i]`, or an index nobody can land on extends `reach`.

Target: Jump Game (LeetCode 55). Before any jump only index 0 is reachable, so the reachable block is 0..0.

Boundary Model: Sorted Coordinate Sweep-Line & Monotonic Stack

Intervals sorted by start coordinate; monotonic stack preserves strictly increasing or decreasing element values.

Loop Invariant Termination

Sweep: if curr.start <= prev.end: merge; Stack: while stack and nums[i] >= stack[-1]: stack.pop().

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

A path search looks necessary here: from index 0 you could jump 1, 2, ... up to nums[0] steps, and every landing spot branches again. Greedy skips the search. A jump may be shorter than its maximum, so if some jump can land on index k, every index before k can be landed on too. The reachable indices are therefore always one unbroken block 0..reach, and a single number, reach, says everything about the past. Walk the array once, and at each index you can stand on, push reach out to i + nums[i] if that is further.

🪜 The Analogy: Stepping Stones Across a River

You cross a river on a row of stepping stones. Each stone has a number painted on it: how many stones ahead you can leap from there, at most. You don't plan a route. You walk along the stones you can reach and keep one note in your head: "the furthest stone I could get to so far." Each new stone may move that note further. If you ever look at a stone beyond the note, nobody can stand on it, and the far bank is out of reach.

🪄 The Mathematical Harmony / Magic Trick
Code / Blueprint
reach = 0
for i in range(len(nums)):
if i > reach:
return False
reach = max(reach, i + nums[i])
return True
 

This is the greedy argument in one line: max keeps the larger block, and a larger block contains every index a smaller one does, so choosing it can never cost an option. A locally best choice that never has to be undone is exactly when greedy is correct. The order of the two lines matters: check i > reach first, so an index nobody can land on never extends reach.

💡 Summary

Keep the furthest reach, not a path. Check i > reach before using nums[i], extend with max, and return True once the loop has stood on every index. One pass: O(N)O(N)O(N) time, O(1)O(1)O(1) space.

  • Extending reach from an index you can't stand on: check i > reach before reach = max(reach, i + nums[i]). On [3,2,1,0,4] index 4 is past reach = 3; letting its jump count returns True instead of False.

  • Assigning instead of taking the max: reach = i + nums[i] lets a short jump after a long one shrink the reach, so [4,1,0,0,0] gets stuck at index 3 and returns False instead of True.

  • Searching paths: trying every jump length from every index is correct but costs up to O(N · max(nums[i])), about 10^9 steps at these limits. One number, reach, replaces the whole search.

  • Answering a different question: reach only says yes or no. The fewest jumps, as in Jump Game II (LC 45), needs a second boundary for where the current jump runs out.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

You will see how a senior engineer spots a greedy reachability question and defends the one-number answer out loud.

Pattern Recognition Signals

The 10-second spot

"The longest jump from each index" and "can you reach the last index": a yes/no reachability question where a longer jump is never worse than a shorter one. When the locally best option (the furthest reach) keeps every choice any other option keeps, that is the signal for Greedy.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Before index i is checked, reach is the furthest index any run of jumps from the indices before i can land on, and every index up to reach can be landed on. If i > reach, return False; otherwise reach = max(reach, i + nums[i]).

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • if i > reach: return False must come before reach = max(reach, i + nums[i]): an index nobody can land on must not extend reach (on [3,2,1,0,4] that would return True).

  • max, not reach = i + nums[i]: a short jump after a long one would shrink the reach ([4,1,0,0,0] would stop at index 3).

  • Don't try every jump length from every index: that is correct but O(N · max(nums[i])), up to 10^9 steps at these limits; a single reach makes it O(N).

The 60-Second Interview Pitch

Say this out loud before you type a single line

I'd solve this with Greedy. I never need the actual path, only the furthest index any sequence of jumps could land on so far; I call it reach. A jump can be shorter than its maximum, so every index up to reach can be landed on, and the reachable indices always form one block from zero to reach. I walk the array once. At each index I first check whether i is past reach: if it is, nobody can stand there, so I return false. Otherwise I extend reach to the max of reach and i plus nums of i. Taking the max never loses an option, because a longer block contains every shorter one. The trap is the order: checking first stops an unreachable index from pushing reach forward. If the loop finishes, I return true. One pass, so O(N) time and O(1) space.

So: keep reach, check i > reach first, extend with max, and say why the larger reach never loses an option.

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the code: reach = 0 is one assignment, and for i in range(len(nums)) visits each index at most once. Its body does one comparison (i > reach) and one max, a constant amount of work, and the loop may stop early at return False. Total: O(N).

SPACE COMPLEXITY

O(1)

The code keeps only reach and i, whatever the input size, and returns one boolean: O(1) extra space.

Formal Recurrence Relation

T(N) = O(1) + N · O(1) = O(N)

Look at the code: reach = 0 is one assignment, and for i in range(len(nums)) visits each index at most once. Its body does one comparison (i > reach) and one max, a constant amount of work, and the loop may stop early at return False. Total: O(N).

Derivation Progression

Start

O(1)

reach = 0 is one assignment.

Index loop

at most N iterations

for i in range(len(nums)) visits each index once, and stops early if return False runs.

Per-index work

O(1) per iteration

One comparison i > reach and one max(reach, i + nums[i]), whatever N is.

Total

O(N)

Constant work per index over at most N indices.

Variable Definitions

NNN

Number of indices, len(nums)

reachreachreach

Furthest index some run of jumps can land on so far

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative, no recursion

🔵 Auxiliary Heap

O(1): reach, i

🟢 Output Space

O(1): one boolean

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1): nums[0] = 0 with more than one index, so the loop returns False at i = 1

Average Case

O(N)O(N)O(N)

Worst Case

O(N)O(N)O(N): the last index is reachable, so every index is checked

Recurrence Tree Topology

Recurrence Tree Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "the longest jump allowed from each index", "can you reach the last index". A yes/no reachability question where a longer jump is never worse than a shorter one: Greedy with one running number, reach.

CONSTRAINTS & BOUNDS

N≤104N \le 10^4N≤104 indices and jumps up to 10510^5105. Trying every jump length from every index costs up to N⋅max⁡(nums[i])≈109N \cdot \max(nums[i]) \approx 10^9N⋅max(nums[i])≈109 steps; the greedy reach is O(N)O(N)O(N) time and O(1)O(1)O(1) space, and it reads nums once, left to right, so it also works on a stream.

FAANG PRODUCTION TRAPS & EDGE CASES

Checking i > reach after the update lets an unreachable index extend the reach. On a stream the same rule means a record that arrives beyond the covered prefix must wait: it can't move the prefix forward. i + nums[i] is at most 104+10510^4 + 10^5104+105, so it fits a 32-bit integer with room to spare.

Core Algorithmic State Invariants

1. One-Block Reach Invariant

Before index `i` is checked, every index from `0` to `reach` can be landed on, because a jump may be shorter than `nums[i]`. The reachable indices are always one unbroken block.

2. Check, Then Extend

`if i > reach: return False` comes first: an index past the block can't be stood on and must never extend it. Otherwise `reach = max(reach, i + nums[i])` keeps the larger block, which contains every option of the smaller one.

3. One Linear Pass

Each index is checked once with O(1) work, so the answer comes in O(N) time and O(1) space; `return True` after the loop means the last index was stood on.

Theory Context•Miscellaneous & Sweeps
MediumLC 55

Jump Game (LeetCode 55)

You will see how one number, the furthest index any jump can reach, replaces a search over every path.

Target Frequency:AmazonGoogleMicrosoft

You get an integer array nums and begin on index 0. The value nums[i] is the longest jump you may make from index i: from there you can move forward by any whole number of steps from 1 up to nums[i], and a value of 0 means you cannot move on from that index.

Return true if some sequence of jumps lands you on the last index, and false if every sequence gets stuck before it.

Worked Examples

Example 1
Input:nums = [2,3,1,1,4]
Output:true
2031121344startjump 1jump 2
Explanation: Index 1 is one step away, and its value `3` carries you straight to index 4, the last index. Other routes work too; one is enough.
Example 2
Input:nums = [3,2,1,0,4]
Output:false
3021120344stuckout of reach
Explanation: Indices 0, 1 and 2 can each get as far as index 3 and no further (`0 + 3`, `1 + 2`, `2 + 1`), and index 3 holds `0`, so no jump ever passes it. Index 4 stays out of reach.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 104

  • 0 <= nums[i] <= 105

Deep-Dive & Conceptual Insights

Why It Works & Core Invariant

You never need the path, only how far any path can get: the reachable indices always form one block 0..reach, so one number and one pass decide the answer.

Real-World Scenario & Production Applications

Any chain of forward hops with a limited range per hop: relay stations along a pipeline, charging stops for a drone, stepping stones on a path. Whether the end can be reached never needs the full route, only the furthest point any route could reach so far, so one running number answers it in a single pass.

Step-by-Step Execution Trace Table

Example 2, nums = [3,2,1,0,4] (the trap case):

inums[i]Check i > reachreach = max(reach, i + nums[i])What it means
030 > 0: nomax(0, 0 + 3) = 3Indices 0 to 3 can be landed on
121 > 3: nomax(3, 1 + 2) = 3No further than before
212 > 3: nomax(3, 2 + 1) = 3No further than before
303 > 3: nomax(3, 3 + 0) = 3Index 3 can't move on
444 > 3: yes(not reached)No jump lands on index 4: return False
Scroll horizontally to see all columns, or expand to full screen
Core Invariant Specification & Code Shape
Archetype Code Shape
Python
1You never need the path, only how far any path can get: keep `reach`, the furthest index a run of jumps can land on so far.
2Every index from `0` to `reach` can be landed on (a jump may be shorter than `nums[i]`), so extend it with `reach = max(reach, i + nums[i])`: the larger reach keeps every option.
3Start `reach = 0`, loop `for i in range(len(nums))` once, and `return True` after the loop.
4The trap: check `if i > reach: return False` before reading `nums[i]`, or an index nobody can land on extends `reach`.

Target: Jump Game (LeetCode 55). Before any jump only index 0 is reachable, so the reachable block is 0..0.

Boundary Model: Sorted Coordinate Sweep-Line & Monotonic Stack

Intervals sorted by start coordinate; monotonic stack preserves strictly increasing or decreasing element values.

Loop Invariant Termination

Sweep: if curr.start <= prev.end: merge; Stack: while stack and nums[i] >= stack[-1]: stack.pop().

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

A path search looks necessary here: from index 0 you could jump 1, 2, ... up to nums[0] steps, and every landing spot branches again. Greedy skips the search. A jump may be shorter than its maximum, so if some jump can land on index k, every index before k can be landed on too. The reachable indices are therefore always one unbroken block 0..reach, and a single number, reach, says everything about the past. Walk the array once, and at each index you can stand on, push reach out to i + nums[i] if that is further.

🪜 The Analogy: Stepping Stones Across a River

You cross a river on a row of stepping stones. Each stone has a number painted on it: how many stones ahead you can leap from there, at most. You don't plan a route. You walk along the stones you can reach and keep one note in your head: "the furthest stone I could get to so far." Each new stone may move that note further. If you ever look at a stone beyond the note, nobody can stand on it, and the far bank is out of reach.

🪄 The Mathematical Harmony / Magic Trick
Code / Blueprint
reach = 0
for i in range(len(nums)):
if i > reach:
return False
reach = max(reach, i + nums[i])
return True
 

This is the greedy argument in one line: max keeps the larger block, and a larger block contains every index a smaller one does, so choosing it can never cost an option. A locally best choice that never has to be undone is exactly when greedy is correct. The order of the two lines matters: check i > reach first, so an index nobody can land on never extends reach.

💡 Summary

Keep the furthest reach, not a path. Check i > reach before using nums[i], extend with max, and return True once the loop has stood on every index. One pass: O(N)O(N)O(N) time, O(1)O(1)O(1) space.

  • Extending reach from an index you can't stand on: check i > reach before reach = max(reach, i + nums[i]). On [3,2,1,0,4] index 4 is past reach = 3; letting its jump count returns True instead of False.

  • Assigning instead of taking the max: reach = i + nums[i] lets a short jump after a long one shrink the reach, so [4,1,0,0,0] gets stuck at index 3 and returns False instead of True.

  • Searching paths: trying every jump length from every index is correct but costs up to O(N · max(nums[i])), about 10^9 steps at these limits. One number, reach, replaces the whole search.

  • Answering a different question: reach only says yes or no. The fewest jumps, as in Jump Game II (LC 45), needs a second boundary for where the current jump runs out.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

You will see how a senior engineer spots a greedy reachability question and defends the one-number answer out loud.

Pattern Recognition Signals

The 10-second spot

"The longest jump from each index" and "can you reach the last index": a yes/no reachability question where a longer jump is never worse than a shorter one. When the locally best option (the furthest reach) keeps every choice any other option keeps, that is the signal for Greedy.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Before index i is checked, reach is the furthest index any run of jumps from the indices before i can land on, and every index up to reach can be landed on. If i > reach, return False; otherwise reach = max(reach, i + nums[i]).

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • if i > reach: return False must come before reach = max(reach, i + nums[i]): an index nobody can land on must not extend reach (on [3,2,1,0,4] that would return True).

  • max, not reach = i + nums[i]: a short jump after a long one would shrink the reach ([4,1,0,0,0] would stop at index 3).

  • Don't try every jump length from every index: that is correct but O(N · max(nums[i])), up to 10^9 steps at these limits; a single reach makes it O(N).

The 60-Second Interview Pitch

Say this out loud before you type a single line

I'd solve this with Greedy. I never need the actual path, only the furthest index any sequence of jumps could land on so far; I call it reach. A jump can be shorter than its maximum, so every index up to reach can be landed on, and the reachable indices always form one block from zero to reach. I walk the array once. At each index I first check whether i is past reach: if it is, nobody can stand there, so I return false. Otherwise I extend reach to the max of reach and i plus nums of i. Taking the max never loses an option, because a longer block contains every shorter one. The trap is the order: checking first stops an unreachable index from pushing reach forward. If the loop finishes, I return true. One pass, so O(N) time and O(1) space.

So: keep reach, check i > reach first, extend with max, and say why the larger reach never loses an option.

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the code: reach = 0 is one assignment, and for i in range(len(nums)) visits each index at most once. Its body does one comparison (i > reach) and one max, a constant amount of work, and the loop may stop early at return False. Total: O(N).

SPACE COMPLEXITY

O(1)

The code keeps only reach and i, whatever the input size, and returns one boolean: O(1) extra space.

Formal Recurrence Relation

T(N) = O(1) + N · O(1) = O(N)

Look at the code: reach = 0 is one assignment, and for i in range(len(nums)) visits each index at most once. Its body does one comparison (i > reach) and one max, a constant amount of work, and the loop may stop early at return False. Total: O(N).

Derivation Progression

Start

O(1)

reach = 0 is one assignment.

Index loop

at most N iterations

for i in range(len(nums)) visits each index once, and stops early if return False runs.

Per-index work

O(1) per iteration

One comparison i > reach and one max(reach, i + nums[i]), whatever N is.

Total

O(N)

Constant work per index over at most N indices.

Variable Definitions

NNN

Number of indices, len(nums)

reachreachreach

Furthest index some run of jumps can land on so far

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative, no recursion

🔵 Auxiliary Heap

O(1): reach, i

🟢 Output Space

O(1): one boolean

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1): nums[0] = 0 with more than one index, so the loop returns False at i = 1

Average Case

O(N)O(N)O(N)

Worst Case

O(N)O(N)O(N): the last index is reachable, so every index is checked

Recurrence Tree Topology

Recurrence Tree Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "the longest jump allowed from each index", "can you reach the last index". A yes/no reachability question where a longer jump is never worse than a shorter one: Greedy with one running number, reach.

CONSTRAINTS & BOUNDS

N≤104N \le 10^4N≤104 indices and jumps up to 10510^5105. Trying every jump length from every index costs up to N⋅max⁡(nums[i])≈109N \cdot \max(nums[i]) \approx 10^9N⋅max(nums[i])≈109 steps; the greedy reach is O(N)O(N)O(N) time and O(1)O(1)O(1) space, and it reads nums once, left to right, so it also works on a stream.

FAANG PRODUCTION TRAPS & EDGE CASES

Checking i > reach after the update lets an unreachable index extend the reach. On a stream the same rule means a record that arrives beyond the covered prefix must wait: it can't move the prefix forward. i + nums[i] is at most 104+10510^4 + 10^5104+105, so it fits a 32-bit integer with room to spare.

Core Algorithmic State Invariants

1. One-Block Reach Invariant

Before index `i` is checked, every index from `0` to `reach` can be landed on, because a jump may be shorter than `nums[i]`. The reachable indices are always one unbroken block.

2. Check, Then Extend

`if i > reach: return False` comes first: an index past the block can't be stood on and must never extend it. Otherwise `reach = max(reach, i + nums[i])` keeps the larger block, which contains every option of the smaller one.

3. One Linear Pass

Each index is checked once with O(1) work, so the answer comes in O(N) time and O(1) space; `return True` after the loop means the last index was stood on.

Rosetta Dual-Monaco Comparison
Python 3
CANONICAL INVARIANT TEMPLATE
Loading...
CONCRETE: JUMP GAME (LEETCODE 55)
T = O(N)S = O(1)
Loading...
Pattern Implementation Mapping TableCanonical Invariant ⟷ Concrete Code ⟷ Engineering Rationale
Canonical InvariantConcrete CodeEngineering Rationale
Summarize the past in one number: the furthest reachable indexreach = 0Before any jump only index 0 is reachable, so the reachable block is 0..0.
Visit every index once, left to rightfor i in range(len(nums)):Each index is either inside the reachable block (it can be stood on) or past it.
Stop when the block ends before i: check before using index iif i > reach: return FalseNo jump lands on index i, so no later index can be reached either. Checking first keeps an unreachable index from extending reach.
Extend with the locally best choicereach = max(reach, i + nums[i])A longer reach contains every index a shorter one does, so max never loses an option.
Every index was reachablereturn TrueThe loop stood on the last index, so the answer is yes.
© 2026 Hi👋WebEnterprise. All rights reserved.
Sitemap•llms.txt•