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
MediumLC 198

House Robber (LeetCode 198)

Target Frequency:MetaAmazonGoogleApple

Houses stand in a row, each holding a known amount of cash, but any two houses sitting right next to each other share a single alarm, so burgling both in one night sets it off.

Given the stash in each house as nums, find the largest total you can collect in one night without ever choosing two adjacent houses.

Worked Examples

Example 1
Input:nums = [1,2,3,1]
Output:4
Explanation: Choosing house 0 (worth 1) and house 2 (worth 3), which are not adjacent, nets 1 + 3 = 4 in total.
Example 2
Input:nums = [2,7,9,3,1]
Output:12
Explanation: Taking house 0 (worth 2), house 2 (worth 9), and house 4 (worth 1) -- none of which touch each other -- adds up to 2 + 9 + 1 = 12.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 100

  • 0 <= nums[i] <= 400

Deep-Dive & Conceptual Insights

Core Insight

Transitions only look back two steps (i - 1 and i - 2). Keeping two scalar variables prev1 and prev2 eliminates the O(N) array allocation entirely.

Real-World Scenario & Production Applications

Resource scheduling with refractory cooldowns, portfolio rebalancing with mandatory cooldown intervals, and adjacent security sensor constraints.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Base Case Initialization

Let prev2 = 0 (the best total up to two houses back) and prev1 = 0 (the best total up to the previous house).

Mathematical Recurrence / Code Invariant
# Base State: 2 rolling scalar registers
prev2 = 0  # Max loot up to house i - 2
prev1 = 0  # Max loot up to house i - 1

Step-by-Step Execution Trace Table

House iHouse ValueOption A: Skip (prev1)Option B: Rob (money + prev2)Chosen dp[i]Rationale
02—2 + 0 = 22Rob house 0.
1727 + 0 = 77Rob house 1 (beats house 0).
2979 + 2 = 1111Rob house 2 + house 0.
33113 + 7 = 1011Skip house 3 (11 > 10), preserving house 4 option!
41111 + 11 = 1212Rob house 4 + house 2 + house 0 →\to→ Max = 12.
Code Shape
Archetype Code Shape
Python
1if not nums:
2 return 0
3prev2, prev1 = 0, 0
4for x in nums:
5 curr = max(prev1, prev2 + x)
6 prev2 = prev1
7 prev1 = curr
8return prev1

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition
Code / Blueprint
House Robber enforces a non-consecutive constraint: adjacent houses trigger alarms. At each house $i$, we face a binary decision: rob house $i$ (yielding $nums[i]$ plus the optimal loot from house $i-2$) or skip house $i$ (retaining the optimal loot from house $i-1$). The recurrence $dp[i] = \max(dp[i-1], dp[i-2] + nums[i])$ depends only on two previous states, enabling $O(N)$ runtime with $O(1)$ scalar memory.
 
🏠 The Analogy: Two Running Totals, One Step Apart

Walk down the street holding two running numbers in your head: "the best I could do up through the previous house" and "the best I could do up through the house before that." At each new house, you have exactly two options: skip it (your total stays whatever the previous house's best was), or rob it (add this house's stash to whatever the best was two houses back, since robbing this one forces you to have skipped the one right before it). Take whichever option is bigger, then shift both running numbers forward by one house.

🔑 The Key Idea in the Code

Only two numbers ever need to be carried forward — not an array of every house's best score — because the decision at any house only ever needs "best up to one house back" and "best up to two houses back," nothing further.

  • Greedy even vs odd alternating choice is flawed: Robbing all even indices or all odd indices is not optimal. Counterexample: [2, 1, 1, 2] yields 2+2=42 + 2 = 42+2=4, whereas even sum is 3 and odd sum is 3. DP is required.

  • A one-house street: an array-based solution that seeds dp[1] = max(nums[0], nums[1]) reads past the end when len(nums) == 1; return nums[0] first, or use the two rolling variables, which need no seeding.

  • Believing you need to check dp[i-3]: Skipping two consecutive houses is never optimal because you could have safely robbed the intermediate house without conflict. Recurrence max(prev1, prev2 + num) is strictly sufficient.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"Maximum sum of non-adjacent elements" + 1D sequential choices with refractory cooldown.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Recurrence: dp[i] = max(dp[i-1], nums[i] + dp[i-2]). Invariant: prev1 stores max profit up to house i-1, prev2 stores max profit up to house i-2.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Shift in the right order: compute curr from the old values, then prev2 = prev1, then prev1 = curr. Writing prev1 = curr first makes prev2 a copy of the new value, so the next house is added on top of its own neighbour.

  • Greedy picks fail: taking every other house (all even or all odd positions) gives 3 on [2, 1, 1, 2], but robbing the two ends gives 4. Only comparing skip (prev1) with rob (prev2 + x) at every house finds it.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use Linear DP. The best total up to a house depends only on the best totals up to the two houses before it, so I don't need a whole table. I keep two numbers: prev1, the best total up to the previous house, and prev2, the best total up to the house before that. At each house I compare two choices: skip it and keep prev1, or rob it and add its money to prev2, because robbing it rules out its neighbour. The larger one is curr, the best total so far. Both numbers already hold the best answer for their part of the street, so these two choices are the only ones I need. The trap is the shift order: I compute curr from the old values first, then move prev1 into prev2 and curr into prev1; overwriting prev1 first would let me rob two neighbours. One pass, so 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] = max(dp[i-1], dp[i-2] + nums[i]). Maintains two rolling variables (prev1, prev2) for maximum loot up to the previous two houses. Single linear pass.

SPACE COMPLEXITY

O(1) Auxiliary

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

Formal Recurrence Relation

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

Derivation Progression

Binary Choice Recurrence

curr = max(prev1, prev2 + x)

Optimal choice is max of skipping current house or robbing it.

Rolling Invariant

prev2, prev1 = prev1, curr

Shifts window forward in O(1).

Linear Scan

N house evaluations = O(N)

Computes max profit in single linear pass.

Variable Definitions

NNN

Total number of houses along the street

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Two integer registers

🟢 Output Space

O(1) Maximum loot integer

Boundary Best / Worst Cases

Best Case

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

Average Case

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

Worst Case

O(N)O(N)O(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: "cannot rob adjacent houses", "maximize the amount of money". Binary include/exclude decision at each element: rob current house (money+rob(i−2)money + rob(i-2)money+rob(i−2)) OR skip current house (rob(i−1)rob(i-1)rob(i−1)).

CONSTRAINTS & BOUNDS

N≤100N \le 100N≤100. Time budget O(N)O(N)O(N). Space budget O(1)O(1)O(1).

FAANG PRODUCTION TRAPS & EDGE CASES

Streams: after each house, prev1 is already the best total for the houses seen so far, so the same two variables answer the question for houses arriving one at a time, with O(1) memory and no second pass. The largest possible answer here is 100 × 400 = 40,000, so overflow is not a concern.

Theory Context•Dynamic Programming
MediumLC 198

House Robber (LeetCode 198)

Target Frequency:MetaAmazonGoogleApple

Houses stand in a row, each holding a known amount of cash, but any two houses sitting right next to each other share a single alarm, so burgling both in one night sets it off.

Given the stash in each house as nums, find the largest total you can collect in one night without ever choosing two adjacent houses.

Worked Examples

Example 1
Input:nums = [1,2,3,1]
Output:4
Explanation: Choosing house 0 (worth 1) and house 2 (worth 3), which are not adjacent, nets 1 + 3 = 4 in total.
Example 2
Input:nums = [2,7,9,3,1]
Output:12
Explanation: Taking house 0 (worth 2), house 2 (worth 9), and house 4 (worth 1) -- none of which touch each other -- adds up to 2 + 9 + 1 = 12.

⚖️Formal Constraints & Bounds

  • 1 <= nums.length <= 100

  • 0 <= nums[i] <= 400

Deep-Dive & Conceptual Insights

Core Insight

Transitions only look back two steps (i - 1 and i - 2). Keeping two scalar variables prev1 and prev2 eliminates the O(N) array allocation entirely.

Real-World Scenario & Production Applications

Resource scheduling with refractory cooldowns, portfolio rebalancing with mandatory cooldown intervals, and adjacent security sensor constraints.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Base Case Initialization

Let prev2 = 0 (the best total up to two houses back) and prev1 = 0 (the best total up to the previous house).

Mathematical Recurrence / Code Invariant
# Base State: 2 rolling scalar registers
prev2 = 0  # Max loot up to house i - 2
prev1 = 0  # Max loot up to house i - 1

Step-by-Step Execution Trace Table

House iHouse ValueOption A: Skip (prev1)Option B: Rob (money + prev2)Chosen dp[i]Rationale
02—2 + 0 = 22Rob house 0.
1727 + 0 = 77Rob house 1 (beats house 0).
2979 + 2 = 1111Rob house 2 + house 0.
33113 + 7 = 1011Skip house 3 (11 > 10), preserving house 4 option!
41111 + 11 = 1212Rob house 4 + house 2 + house 0 →\to→ Max = 12.
Code Shape
Archetype Code Shape
Python
1if not nums:
2 return 0
3prev2, prev1 = 0, 0
4for x in nums:
5 curr = max(prev1, prev2 + x)
6 prev2 = prev1
7 prev1 = curr
8return prev1

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition
Code / Blueprint
House Robber enforces a non-consecutive constraint: adjacent houses trigger alarms. At each house $i$, we face a binary decision: rob house $i$ (yielding $nums[i]$ plus the optimal loot from house $i-2$) or skip house $i$ (retaining the optimal loot from house $i-1$). The recurrence $dp[i] = \max(dp[i-1], dp[i-2] + nums[i])$ depends only on two previous states, enabling $O(N)$ runtime with $O(1)$ scalar memory.
 
🏠 The Analogy: Two Running Totals, One Step Apart

Walk down the street holding two running numbers in your head: "the best I could do up through the previous house" and "the best I could do up through the house before that." At each new house, you have exactly two options: skip it (your total stays whatever the previous house's best was), or rob it (add this house's stash to whatever the best was two houses back, since robbing this one forces you to have skipped the one right before it). Take whichever option is bigger, then shift both running numbers forward by one house.

🔑 The Key Idea in the Code

Only two numbers ever need to be carried forward — not an array of every house's best score — because the decision at any house only ever needs "best up to one house back" and "best up to two houses back," nothing further.

  • Greedy even vs odd alternating choice is flawed: Robbing all even indices or all odd indices is not optimal. Counterexample: [2, 1, 1, 2] yields 2+2=42 + 2 = 42+2=4, whereas even sum is 3 and odd sum is 3. DP is required.

  • A one-house street: an array-based solution that seeds dp[1] = max(nums[0], nums[1]) reads past the end when len(nums) == 1; return nums[0] first, or use the two rolling variables, which need no seeding.

  • Believing you need to check dp[i-3]: Skipping two consecutive houses is never optimal because you could have safely robbed the intermediate house without conflict. Recurrence max(prev1, prev2 + num) is strictly sufficient.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"Maximum sum of non-adjacent elements" + 1D sequential choices with refractory cooldown.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Recurrence: dp[i] = max(dp[i-1], nums[i] + dp[i-2]). Invariant: prev1 stores max profit up to house i-1, prev2 stores max profit up to house i-2.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Shift in the right order: compute curr from the old values, then prev2 = prev1, then prev1 = curr. Writing prev1 = curr first makes prev2 a copy of the new value, so the next house is added on top of its own neighbour.

  • Greedy picks fail: taking every other house (all even or all odd positions) gives 3 on [2, 1, 1, 2], but robbing the two ends gives 4. Only comparing skip (prev1) with rob (prev2 + x) at every house finds it.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use Linear DP. The best total up to a house depends only on the best totals up to the two houses before it, so I don't need a whole table. I keep two numbers: prev1, the best total up to the previous house, and prev2, the best total up to the house before that. At each house I compare two choices: skip it and keep prev1, or rob it and add its money to prev2, because robbing it rules out its neighbour. The larger one is curr, the best total so far. Both numbers already hold the best answer for their part of the street, so these two choices are the only ones I need. The trap is the shift order: I compute curr from the old values first, then move prev1 into prev2 and curr into prev1; overwriting prev1 first would let me rob two neighbours. One pass, so 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] = max(dp[i-1], dp[i-2] + nums[i]). Maintains two rolling variables (prev1, prev2) for maximum loot up to the previous two houses. Single linear pass.

SPACE COMPLEXITY

O(1) Auxiliary

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

Formal Recurrence Relation

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

Derivation Progression

Binary Choice Recurrence

curr = max(prev1, prev2 + x)

Optimal choice is max of skipping current house or robbing it.

Rolling Invariant

prev2, prev1 = prev1, curr

Shifts window forward in O(1).

Linear Scan

N house evaluations = O(N)

Computes max profit in single linear pass.

Variable Definitions

NNN

Total number of houses along the street

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(1) Two integer registers

🟢 Output Space

O(1) Maximum loot integer

Boundary Best / Worst Cases

Best Case

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

Average Case

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

Worst Case

O(N)O(N)O(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: "cannot rob adjacent houses", "maximize the amount of money". Binary include/exclude decision at each element: rob current house (money+rob(i−2)money + rob(i-2)money+rob(i−2)) OR skip current house (rob(i−1)rob(i-1)rob(i−1)).

CONSTRAINTS & BOUNDS

N≤100N \le 100N≤100. Time budget O(N)O(N)O(N). Space budget O(1)O(1)O(1).

FAANG PRODUCTION TRAPS & EDGE CASES

Streams: after each house, prev1 is already the best total for the houses seen so far, so the same two variables answer the question for houses arriving one at a time, with O(1) memory and no second pass. The largest possible answer here is 100 × 400 = 40,000, so overflow is not a concern.

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