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 72

Edit Distance (LeetCode 72)

Target Frequency:GoogleAmazonMicrosoft

You have two strings, word1 and word2, and three single-character edits at your disposal: insert one, delete one, or replace one.

Work out the fewest such edits needed to transform word1 into word2.

Worked Examples

Example 1
Input:word1 = "horse", word2 = "ros"
Output:3
Explanation: Swap the 'h' for 'r' to turn horse into rorse, drop the 'r' to get rose, then drop the trailing 'e' to reach ros -- three edits.
Example 2
Input:word1 = "intention", word2 = "execution"
Output:5
Explanation: Five edits get there: drop the 't' in intention to get inention; swap the leading 'i' for 'e' to get enention; swap the next 'n' for 'x' to get exention; swap the following 'n' for 'c' to get exection; then insert a 'u' to land on execution.

⚖️Formal Constraints & Bounds

  • 0 <= word1.length, word2.length <= 500

  • word1 and word2 consist of lowercase English letters.

Deep-Dive & Conceptual Insights

Core Insight

2D matrix evaluates all three edit operations simultaneously to guarantee global minimal edit distance.

Real-World Scenario & Production Applications

Spell checker auto-correction, DNA string sequence alignment.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Boundary Base States (Insertions / Deletions)

Converting an empty string to a prefix of length j requires j insertions (dp[0][j] = j). Converting a prefix of length i to an empty string requires i deletions (dp[i][0] = i).

Mathematical Recurrence / Code Invariant
# Base row & column:
for i in range(M + 1): dp[i][0] = i  # Deletions
for j in range(N + 1): dp[0][j] = j  # Insertions

Step-by-Step Execution Trace Table

Char PairActiondp Cell Value
('h', 'r')Replace 'h' -> 'r'1
('o', 'o')Match! inherit diagonal1
('r', 's')Replace/Delete2
Final (5, 3)Total minimal operations3
Code Shape
Archetype Code Shape
Python
1dp = [[0] * (n + 1) for _ in range(m + 1)]
2for i in range(m + 1):
3 dp[i][0] = i
4for j in range(n + 1):
5 dp[0][j] = j
6for i in range(1, m + 1):
7 for j in range(1, n + 1):
8 if word1[i-1] == word2[j-1]:
9 dp[i][j] = dp[i-1][j-1]
10 else:
11 dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])
12return dp[m][n]

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition
Code / Blueprint
Edit Distance measures the minimum operations (insert, delete, replace) to transform $word_1$ into $word_2$. At matrix cell $(i, j)$, if characters match, cost is free ($dp[i-1][j-1]$). If they differ, we take $1 + \min(\text{insert: } dp[i][j-1], \text{delete: } dp[i-1][j], \text{replace: } dp[i-1][j-1])$. Initializing boundary rows to prefix deletion and insertion costs guarantees exact Levenshtein distance in $O(M \times N)$ time.
 
✏️ The Analogy: Proofreading Two Drafts Into Alignment

Imagine transforming one draft of a document into another, one character at a time, tracking your progress in a grid where cell (i, j) means "cost to turn the first i letters of word1 into the first j letters of word2." If the current letters already match, no edit is needed here at all — inherit the cost from before either letter was considered. If they don't match, you have exactly three moves available, and you take whichever is cheapest: delete a letter from word1 (move up a row), insert a letter to match word2 (move left a column), or replace the letter outright (move diagonally) — each costing one edit on top of the smaller sub-problem's already-known cost.

🔑 The Key Idea in the Code

Each of the three directions in the grid corresponds to exactly one edit operation — up is delete, left is insert, diagonal is replace — so the minimum edit distance is really the cheapest path through this grid from corner to corner.

  • Mismatch branch cost omission: Writing min(insert, delete, replace) without adding +1+1+1 to the mismatch transition: dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]).

  • Match branch cost inflation: Adding +1+1+1 when characters match (word1[i-1] == word2[j-1]). Matching characters cost 0 operations; the transition must inherit the diagonal directly: dp[i][j] = dp[i-1][j-1].

  • Base case non-zero initialization: Failing to initialize dp[i][0] = i (deleting all iii chars) and dp[0][j] = j (inserting all jjj chars). Leaving base rows as zero corrupts the entire alignment calculation.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Minimum transformation steps between two strings using insertions, deletions, replacements.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: dp[i][j] stores the edit distance between word1[:i] and word2[:j].

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Off-by-one indexing between 1-indexed DP table and 0-indexed string characters.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I allocate an (m+1) x (n+1) DP table and initialize border distances dp[i][0] = i and dp[0][j] = j. For each pair (i, j), if word1[i-1] == word2[j-1], dp[i][j] = dp[i-1][j-1]. Otherwise, dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]). Runs in O(M · N) time and O(M · N) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(M · N)

Look at the execution steps: 2D DP table for word1 of length M and word2 of length N. If characters match, take diagonal; else 1 + min(insert, delete, replace). Rolling row optimization reduces space to O(min(M, N)).

SPACE COMPLEXITY

O(min(M, N)) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Two rows of size min(M, N) + 1.

Formal Recurrence Relation

T(M, N) = M · N = O(M · N)

Derivation Progression

3-Branch Transition

1 + min(insert, delete, replace)

Evaluates all 3 edit operations in O(1) per cell.

Diagonal Match Shortcut

if w1[i-1] == w2[j-1]: dp[i][j] = dp[i-1][j-1]

Free advance when characters match.

Linear Space Compression

O(min(M, N)) row buffers

Retains only active and previous row.

Variable Definitions

MMM

Length of source string word1

NNN

Length of target string word2

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(min(M, N)) 1D rolling array

🟢 Output Space

O(1) Min edits integer

Boundary Best / Worst Cases

Best Case

O(M⋅N)O(M · N)O(M⋅N)

Average Case

O(M⋅N)O(M · N)O(M⋅N)

Worst Case

O(M⋅N)O(M · N)O(M⋅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: "minimum operations to convert word1 to word2", "insert, delete, replace". Levenshtein Distance Matrix: - If characters match: dp[i−1][j−1]dp[i-1][j-1]dp[i−1][j−1] (free). - Else: 1+min⁡(dp[i][j−1] [insert],dp[i−1][j] [delete],dp[i−1][j−1] [replace])1 + \min(dp[i][j-1] \text{ [insert]}, dp[i-1][j] \text{ [delete]}, dp[i-1][j-1] \text{ [replace]})1+min(dp[i][j−1] [insert],dp[i−1][j] [delete],dp[i−1][j−1] [replace]).

CONSTRAINTS & BOUNDS

M,N≤500  ⟹  MN≤2.5×105M, N \le 500 \implies MN \le 2.5 \times 10^5M,N≤500⟹MN≤2.5×105. Time budget O(MN)O(MN)O(MN) runs in <50< 50<50ms.

FAANG PRODUCTION TRAPS & EDGE CASES

Off-by-one in 1-indexed array: w1[i−1]w_1[i-1]w1​[i−1] and w2[j−1]w_2[j-1]w2​[j−1].

Theory Context•Dynamic Programming
MediumLC 72

Edit Distance (LeetCode 72)

Target Frequency:GoogleAmazonMicrosoft

You have two strings, word1 and word2, and three single-character edits at your disposal: insert one, delete one, or replace one.

Work out the fewest such edits needed to transform word1 into word2.

Worked Examples

Example 1
Input:word1 = "horse", word2 = "ros"
Output:3
Explanation: Swap the 'h' for 'r' to turn horse into rorse, drop the 'r' to get rose, then drop the trailing 'e' to reach ros -- three edits.
Example 2
Input:word1 = "intention", word2 = "execution"
Output:5
Explanation: Five edits get there: drop the 't' in intention to get inention; swap the leading 'i' for 'e' to get enention; swap the next 'n' for 'x' to get exention; swap the following 'n' for 'c' to get exection; then insert a 'u' to land on execution.

⚖️Formal Constraints & Bounds

  • 0 <= word1.length, word2.length <= 500

  • word1 and word2 consist of lowercase English letters.

Deep-Dive & Conceptual Insights

Core Insight

2D matrix evaluates all three edit operations simultaneously to guarantee global minimal edit distance.

Real-World Scenario & Production Applications

Spell checker auto-correction, DNA string sequence alignment.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Boundary Base States (Insertions / Deletions)

Converting an empty string to a prefix of length j requires j insertions (dp[0][j] = j). Converting a prefix of length i to an empty string requires i deletions (dp[i][0] = i).

Mathematical Recurrence / Code Invariant
# Base row & column:
for i in range(M + 1): dp[i][0] = i  # Deletions
for j in range(N + 1): dp[0][j] = j  # Insertions

Step-by-Step Execution Trace Table

Char PairActiondp Cell Value
('h', 'r')Replace 'h' -> 'r'1
('o', 'o')Match! inherit diagonal1
('r', 's')Replace/Delete2
Final (5, 3)Total minimal operations3
Code Shape
Archetype Code Shape
Python
1dp = [[0] * (n + 1) for _ in range(m + 1)]
2for i in range(m + 1):
3 dp[i][0] = i
4for j in range(n + 1):
5 dp[0][j] = j
6for i in range(1, m + 1):
7 for j in range(1, n + 1):
8 if word1[i-1] == word2[j-1]:
9 dp[i][j] = dp[i-1][j-1]
10 else:
11 dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])
12return dp[m][n]

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition
Code / Blueprint
Edit Distance measures the minimum operations (insert, delete, replace) to transform $word_1$ into $word_2$. At matrix cell $(i, j)$, if characters match, cost is free ($dp[i-1][j-1]$). If they differ, we take $1 + \min(\text{insert: } dp[i][j-1], \text{delete: } dp[i-1][j], \text{replace: } dp[i-1][j-1])$. Initializing boundary rows to prefix deletion and insertion costs guarantees exact Levenshtein distance in $O(M \times N)$ time.
 
✏️ The Analogy: Proofreading Two Drafts Into Alignment

Imagine transforming one draft of a document into another, one character at a time, tracking your progress in a grid where cell (i, j) means "cost to turn the first i letters of word1 into the first j letters of word2." If the current letters already match, no edit is needed here at all — inherit the cost from before either letter was considered. If they don't match, you have exactly three moves available, and you take whichever is cheapest: delete a letter from word1 (move up a row), insert a letter to match word2 (move left a column), or replace the letter outright (move diagonally) — each costing one edit on top of the smaller sub-problem's already-known cost.

🔑 The Key Idea in the Code

Each of the three directions in the grid corresponds to exactly one edit operation — up is delete, left is insert, diagonal is replace — so the minimum edit distance is really the cheapest path through this grid from corner to corner.

  • Mismatch branch cost omission: Writing min(insert, delete, replace) without adding +1+1+1 to the mismatch transition: dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]).

  • Match branch cost inflation: Adding +1+1+1 when characters match (word1[i-1] == word2[j-1]). Matching characters cost 0 operations; the transition must inherit the diagonal directly: dp[i][j] = dp[i-1][j-1].

  • Base case non-zero initialization: Failing to initialize dp[i][0] = i (deleting all iii chars) and dp[0][j] = j (inserting all jjj chars). Leaving base rows as zero corrupts the entire alignment calculation.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Minimum transformation steps between two strings using insertions, deletions, replacements.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: dp[i][j] stores the edit distance between word1[:i] and word2[:j].

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Off-by-one indexing between 1-indexed DP table and 0-indexed string characters.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I allocate an (m+1) x (n+1) DP table and initialize border distances dp[i][0] = i and dp[0][j] = j. For each pair (i, j), if word1[i-1] == word2[j-1], dp[i][j] = dp[i-1][j-1]. Otherwise, dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]). Runs in O(M · N) time and O(M · N) space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(M · N)

Look at the execution steps: 2D DP table for word1 of length M and word2 of length N. If characters match, take diagonal; else 1 + min(insert, delete, replace). Rolling row optimization reduces space to O(min(M, N)).

SPACE COMPLEXITY

O(min(M, N)) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Two rows of size min(M, N) + 1.

Formal Recurrence Relation

T(M, N) = M · N = O(M · N)

Derivation Progression

3-Branch Transition

1 + min(insert, delete, replace)

Evaluates all 3 edit operations in O(1) per cell.

Diagonal Match Shortcut

if w1[i-1] == w2[j-1]: dp[i][j] = dp[i-1][j-1]

Free advance when characters match.

Linear Space Compression

O(min(M, N)) row buffers

Retains only active and previous row.

Variable Definitions

MMM

Length of source string word1

NNN

Length of target string word2

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(min(M, N)) 1D rolling array

🟢 Output Space

O(1) Min edits integer

Boundary Best / Worst Cases

Best Case

O(M⋅N)O(M · N)O(M⋅N)

Average Case

O(M⋅N)O(M · N)O(M⋅N)

Worst Case

O(M⋅N)O(M · N)O(M⋅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: "minimum operations to convert word1 to word2", "insert, delete, replace". Levenshtein Distance Matrix: - If characters match: dp[i−1][j−1]dp[i-1][j-1]dp[i−1][j−1] (free). - Else: 1+min⁡(dp[i][j−1] [insert],dp[i−1][j] [delete],dp[i−1][j−1] [replace])1 + \min(dp[i][j-1] \text{ [insert]}, dp[i-1][j] \text{ [delete]}, dp[i-1][j-1] \text{ [replace]})1+min(dp[i][j−1] [insert],dp[i−1][j] [delete],dp[i−1][j−1] [replace]).

CONSTRAINTS & BOUNDS

M,N≤500  ⟹  MN≤2.5×105M, N \le 500 \implies MN \le 2.5 \times 10^5M,N≤500⟹MN≤2.5×105. Time budget O(MN)O(MN)O(MN) runs in <50< 50<50ms.

FAANG PRODUCTION TRAPS & EDGE CASES

Off-by-one in 1-indexed array: w1[i−1]w_1[i-1]w1​[i−1] and w2[j−1]w_2[j-1]w2​[j−1].

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