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).

13 Core Algorithmic Patterns & 225 Practice Problems

  • 1. Two Pointers (16 Paradigms, 43 Problems): Opposite ends, sorted pair sums, palindrome verification, trapping rain water, 3Sum, container with most water — includes the Sliding Window and Fast & Slow Pointers paradigms (contiguous subarray invariants, longest substrings, Floyd's cycle detection, linked list middle).
  • 2. Binary Search (9 Paradigms, 14 Problems): Monotonic predicate partitioning (feasible(x)), boundary search, rotated sorted arrays, square roots, minimum ship capacity, median of two sorted arrays, matrix median on value range.
  • 3. Bit Manipulation (5 Paradigms, 11 Problems): Counting set bits, XOR cancellation, bit reversal, bitmask pairing, maximum XOR with a bitwise trie.
  • 4. Math & Geometry (8 Paradigms, 14 Problems): Sieve of Eratosthenes, integer/roman conversions, modular arithmetic, geometric simulation.
  • 5. Tree/Graph Depth-First Search (15 Paradigms, 24 Problems): Path sums, lowest common ancestor, tree diameter, validating BSTs, tree DP (House Robber III, Binary Tree Cameras).
  • 6. Tree/Graph Breadth-First Search (5 Paradigms, 12 Problems): Level-order traversals, shortest path in unweighted graphs, zig-zag traversals, rotting oranges, word ladders.
  • 7. Graphs (12 Paradigms, 22 Problems): Topological sort, cycle detection, Dijkstra's algorithm, bipartite graph validation, network delay.
  • 8. Backtracking (6 Paradigms, 14 Problems): Subsets, permutations, combinations, constraint satisfaction, pruning, N-Queens, Sudoku solver.
  • 9. Dynamic Programming (13 Paradigms, 28 Problems): Memoization vs tabulation, 0/1 knapsack, unbounded knapsack, coin change, edit distance, longest common subsequence.
  • 10. Heap / Priority Queue (9 Paradigms, 11 Problems): Running medians, top-k elements, interval scheduling, IPO, k-way merges.
  • 11. Advanced Data Structures (7 Paradigms, 17 Problems): Trie (prefix tree), Union-Find (Disjoint Set Union), LRU Cache, LFU Cache, range-sum queries with updates.
  • 12. Stack (5 Paradigms, 9 Problems): Next greater element, largest rectangle in histogram, remove k digits, decode string, min stack.
  • 13. Intervals & Greedy (2 Paradigms, 6 Problems): Merge intervals, interval scheduling, meeting rooms by sweep line, jump game.

4-Stage Deliberate Practice Framework

  1. Stage 1 (Compare & Learn): Read the pattern's mental model, loop invariant and Big-O proof, compare the pattern's template with the problem's solution side by side, and use the step-by-step debugger. The solution can also be shown in C#, Java, TypeScript, C++, Go or Rust for almost every problem.
  2. Stage 2 (Active Recall): Rebuild the solution from memory in a code editor, with an invariant checklist and optional progressive hints, and check it against a judged test suite.
  3. Stage 3 (AI Interview Coach, coming soon): A mock-interview stage still in development; for now, students go straight from Stage 2 to Stage 4.
  4. Stage 4 (Solve on Your Own): Solve a new problem on your own against a 15-minute timer; your code is graded against a test suite. Python and TypeScript run in your browser and C# runs on our server (design problems grade in Python and TypeScript).

Equipped with a spaced-repetition review hub on a fixed 7-step schedule (1 day up to 90 days), a two-pane Studio workspace, and study notes.

Pricing, Access & Commercial Terms

  • Core Curriculum: 100% Free. No credit card required.
  • Coins: New accounts get 40 free coins once, the daily claim adds +20 coins once a day, and inviting a friend earns you +25 coins when they complete their first practice step. These are the only ways to earn coins.
  • AI Coach: Each AI coach question costs 1-5 coins, priced by the server according to its size.
  • BYOK (Bring Your Own Key): AI coaching is free with your own Google Gemini, OpenAI or OpenRouter API key (BYOK).
  • Extras: Coins also unlock extras for 24 hours: a Recall hint level (1 coin), a Solve solution reveal (2), a LeetCode problem card's solutions (1) and a pattern's extra canonical problems (1).
  • Payments & Refunds: Nothing on the site is sold for money: coins can only be earned, never bought. There are no subscriptions or charges, so there is nothing to refund.
  • Platform Operator: Hi👋WebEnterprise. Support & policies at hispeedalgo.com.
Skip to main content
Hi👋SpeedAlgo

Invariant-First Algorithmic Mastery

Arena
238Items
Theory Context•Dynamic Programming
EasyLC 70

Climbing Stairs (LeetCode 70)

Target Frequency:GoogleAmazonMicrosoft

A staircase has n steps between you and the top, and on every move you advance exactly 1 or 2 steps.

Count how many distinct sequences of moves get you all the way from the bottom to step n.

Worked Examples

Example 1
Input:n = 2
Output:2
Explanation: Two move sequences reach the top: two single steps in a row, or one double step.
Example 2
Input:n = 3
Output:3
Explanation: Three move sequences reach the top: three single steps; a single step then a double step; or a double step then a single step.

⚖️Formal Constraints & Bounds

  • 1 <= n <= 45

Deep-Dive & Conceptual Insights

Core Insight

Two rolling state variables eliminate all array allocation, achieving O(1) auxiliary memory.

Real-World Scenario & Production Applications

Staircase step counting, sequence tiling combinatorics.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Base Step Anchors

There is 1 way to reach step 1 (a = 1) and 2 ways to reach step 2 (b = 2).

Mathematical Recurrence / Code Invariant
a, b = 1, 2  # 1 step: 1 way, 2 steps: 2 ways

Step-by-Step Execution Trace Table

Step nWays(n-2)Ways(n-1)Ways(n) = Sum
1--1
2--2
3123
4235
5358
Code Shape
Archetype Code Shape
Python
1prev2, prev1 = 1, 1
2for _ in range(2, n + 1):
3 curr = prev1 + prev2
4 prev2 = prev1
5 prev1 = curr
6return prev1

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Climbing Stairs is the quintessential linear recurrence relation. The naive recursive solution branches twice at every step, creating a call tree of size O(2N)O(2^N)O(2N) filled with duplicate calculations of subproblems like climbStairs(n-3). By recognizing that the state space is a DAG(Directed Acyclic Graph) with NNN vertices and 2N2N2N edges, we invert the computation into a bottom-up sweep. Starting from base cases dp[1]=1dp[1] = 1dp[1]=1 and dp[2]=2dp[2] = 2dp[2]=2, we compute each successive state in O(1)O(1)O(1) time.

🏟️ The Analogy: Dominoes Falling Forward

Imagine laying out a line of dominoes where the force needed to topple domino iii comes from the combined impact of domino i−1i-1i−1 and domino i−2i-2i−2. You know the exact force of the first two dominoes. Rather than asking "what made domino NNN fall?" and tracing backward through a branching tree of questions that grows exponentially, you simply push domino 1 and 2 forward. The wave of computation propagates linearly from left to right, solving each step once and for all.

🔑 Why It Works

Python's tuple unpacking a, b = b, a + b captures the recurrence transition atomically without temporary variables, evaluating the NNN-th Fibonacci state in O(N)O(N)O(N) time and O(1)O(1)O(1) memory.

  • Base case index mapping: N=1N=1N=1 has 1 way, N=2N=2N=2 has 2 ways. Forgetting to handle N=1N=1N=1 separately when pre-allocating an array of size 2 causes IndexError.

  • Integer overflow in typed languages: For large NNN (or Fibonacci variants), intermediate values exceed 32-bit signed ints; use 64-bit types or BigInt.

  • Over-complicating with matrix exponentiation: While O(log⁡N)O(\log N)O(logN) matrix exponentiation exists, for N≤45N \le 45N≤45 simple linear rolling iteration is cleanest and runs in <1< 1<1 ms.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Linear step progression where each step depends on the previous 1 or 2 steps.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: after each step i, prev1 is the number of ways to reach step i and prev2 is the number of ways to reach step i - 1.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Setting prev1 = curr before prev2 = prev1, so both variables hold the same value.

  • Starting from 1, 2 while the loop starts at step 2, which makes every answer one step too far along.

  • Using recursion without memoization (O(2^N) time).

  • Allocating an O(N) array when only 2 scalar variables are needed.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I start with prev2 = 1 and prev1 = 1: one way to stand on step 0 and one way to reach step 1. From step 2 to n, I compute curr = prev1 + prev2, then set prev2 = prev1 and prev1 = curr, in that order. I return prev1. Runs in O(N) time and O(1) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the execution steps: dp[i] = dp[i-1] + dp[i-2]. Since each state depends only on previous 2 values, rolling variables (prev1, prev2) compute answer in N additions.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Only stores 2 scalar integer registers.

Formal Recurrence Relation

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

Derivation Progression

Recurrence Invariant

f(n) = f(n-1) + f(n-2)

Can arrive at step n from step n-1 (1 step) or step n-2 (2 steps).

Rolling Variable State Update

a, b = b, a + b

Updates state in O(1) time per step.

Linear Time Bound

N additions = O(N)

Computes exact Fibonacci sequence in linear time.

Variable Definitions

NNN

Total number of staircase steps

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Two scalar variables

🟢 Output Space

O(1) Integer count

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1) for N <= 2.

Average Case

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

Worst Case

O(N)O(N)O(N) for arbitrary N.

State-Space & Subproblem DAG(Directed Acyclic Graph) Topology

State-Space & Subproblem DAG(Directed Acyclic Graph) Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "climb 1 or 2 steps", "distinct ways to reach the top". Canonical Fibonacci recurrence: to reach step nnn, you must have jumped from step n−1n-1n−1 (1 step) or step n−2n-2n−2 (2 steps): ways(n)=ways(n−1)+ways(n−2)ways(n) = ways(n-1) + ways(n-2)ways(n)=ways(n−1)+ways(n−2).

CONSTRAINTS & BOUNDS

1≤n≤451 \le n \le 451≤n≤45. Time budget O(N)O(N)O(N).

FAANG PRODUCTION TRAPS & EDGE CASES

Allocating an O(N)O(N)O(N) array: senior systems engineering optimizes space to strictly O(1)O(1)O(1) via rolling variables.

Theory Context•Dynamic Programming
EasyLC 70

Climbing Stairs (LeetCode 70)

Target Frequency:GoogleAmazonMicrosoft

A staircase has n steps between you and the top, and on every move you advance exactly 1 or 2 steps.

Count how many distinct sequences of moves get you all the way from the bottom to step n.

Worked Examples

Example 1
Input:n = 2
Output:2
Explanation: Two move sequences reach the top: two single steps in a row, or one double step.
Example 2
Input:n = 3
Output:3
Explanation: Three move sequences reach the top: three single steps; a single step then a double step; or a double step then a single step.

⚖️Formal Constraints & Bounds

  • 1 <= n <= 45

Deep-Dive & Conceptual Insights

Core Insight

Two rolling state variables eliminate all array allocation, achieving O(1) auxiliary memory.

Real-World Scenario & Production Applications

Staircase step counting, sequence tiling combinatorics.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Base Step Anchors

There is 1 way to reach step 1 (a = 1) and 2 ways to reach step 2 (b = 2).

Mathematical Recurrence / Code Invariant
a, b = 1, 2  # 1 step: 1 way, 2 steps: 2 ways

Step-by-Step Execution Trace Table

Step nWays(n-2)Ways(n-1)Ways(n) = Sum
1--1
2--2
3123
4235
5358
Code Shape
Archetype Code Shape
Python
1prev2, prev1 = 1, 1
2for _ in range(2, n + 1):
3 curr = prev1 + prev2
4 prev2 = prev1
5 prev1 = curr
6return prev1

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

Climbing Stairs is the quintessential linear recurrence relation. The naive recursive solution branches twice at every step, creating a call tree of size O(2N)O(2^N)O(2N) filled with duplicate calculations of subproblems like climbStairs(n-3). By recognizing that the state space is a DAG(Directed Acyclic Graph) with NNN vertices and 2N2N2N edges, we invert the computation into a bottom-up sweep. Starting from base cases dp[1]=1dp[1] = 1dp[1]=1 and dp[2]=2dp[2] = 2dp[2]=2, we compute each successive state in O(1)O(1)O(1) time.

🏟️ The Analogy: Dominoes Falling Forward

Imagine laying out a line of dominoes where the force needed to topple domino iii comes from the combined impact of domino i−1i-1i−1 and domino i−2i-2i−2. You know the exact force of the first two dominoes. Rather than asking "what made domino NNN fall?" and tracing backward through a branching tree of questions that grows exponentially, you simply push domino 1 and 2 forward. The wave of computation propagates linearly from left to right, solving each step once and for all.

🔑 Why It Works

Python's tuple unpacking a, b = b, a + b captures the recurrence transition atomically without temporary variables, evaluating the NNN-th Fibonacci state in O(N)O(N)O(N) time and O(1)O(1)O(1) memory.

  • Base case index mapping: N=1N=1N=1 has 1 way, N=2N=2N=2 has 2 ways. Forgetting to handle N=1N=1N=1 separately when pre-allocating an array of size 2 causes IndexError.

  • Integer overflow in typed languages: For large NNN (or Fibonacci variants), intermediate values exceed 32-bit signed ints; use 64-bit types or BigInt.

  • Over-complicating with matrix exponentiation: While O(log⁡N)O(\log N)O(logN) matrix exponentiation exists, for N≤45N \le 45N≤45 simple linear rolling iteration is cleanest and runs in <1< 1<1 ms.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Linear step progression where each step depends on the previous 1 or 2 steps.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: after each step i, prev1 is the number of ways to reach step i and prev2 is the number of ways to reach step i - 1.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Setting prev1 = curr before prev2 = prev1, so both variables hold the same value.

  • Starting from 1, 2 while the loop starts at step 2, which makes every answer one step too far along.

  • Using recursion without memoization (O(2^N) time).

  • Allocating an O(N) array when only 2 scalar variables are needed.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I start with prev2 = 1 and prev1 = 1: one way to stand on step 0 and one way to reach step 1. From step 2 to n, I compute curr = prev1 + prev2, then set prev2 = prev1 and prev1 = curr, in that order. I return prev1. Runs in O(N) time and O(1) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the execution steps: dp[i] = dp[i-1] + dp[i-2]. Since each state depends only on previous 2 values, rolling variables (prev1, prev2) compute answer in N additions.

SPACE COMPLEXITY

O(1) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Only stores 2 scalar integer registers.

Formal Recurrence Relation

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

Derivation Progression

Recurrence Invariant

f(n) = f(n-1) + f(n-2)

Can arrive at step n from step n-1 (1 step) or step n-2 (2 steps).

Rolling Variable State Update

a, b = b, a + b

Updates state in O(1) time per step.

Linear Time Bound

N additions = O(N)

Computes exact Fibonacci sequence in linear time.

Variable Definitions

NNN

Total number of staircase steps

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Two scalar variables

🟢 Output Space

O(1) Integer count

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1) for N <= 2.

Average Case

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

Worst Case

O(N)O(N)O(N) for arbitrary N.

State-Space & Subproblem DAG(Directed Acyclic Graph) Topology

State-Space & Subproblem DAG(Directed Acyclic Graph) Topology
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "climb 1 or 2 steps", "distinct ways to reach the top". Canonical Fibonacci recurrence: to reach step nnn, you must have jumped from step n−1n-1n−1 (1 step) or step n−2n-2n−2 (2 steps): ways(n)=ways(n−1)+ways(n−2)ways(n) = ways(n-1) + ways(n-2)ways(n)=ways(n−1)+ways(n−2).

CONSTRAINTS & BOUNDS

1≤n≤451 \le n \le 451≤n≤45. Time budget O(N)O(N)O(N).

FAANG PRODUCTION TRAPS & EDGE CASES

Allocating an O(N)O(N)O(N) array: senior systems engineering optimizes space to strictly O(1)O(1)O(1) via rolling variables.

© 2026 Hi👋WebEnterprise. All rights reserved.
Sitemap•llms.txt•