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•Advanced Data Structures
MediumLC 211

Design Add and Search Words Data Structure (LeetCode 211)

Target Frequency:MetaAmazonGoogleApple

Build a structure that can remember a growing set of words and later test whether a query string matches any of them.

Implement a WordDictionary class:

  • WordDictionary() starts with an empty set of words.
  • void addWord(word) remembers word so later searches can match it.
  • bool search(word) returns true if some remembered word matches word, else false. In word, a . character stands in for any single letter.

Worked Examples

Example 1
Input:["WordDictionary","addWord","addWord","addWord","search","search","search","search"] [[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
Output:[null,null,null,null,false,true,true,true]
Explanation: "pad" was never added. "bad" was. ".ad" matches "bad", "dad" or "mad", and "b.." matches "bad".

⚖️Formal Constraints & Bounds

  • 1 <= word.length <= 25

  • word in addWord consists of lowercase English letters.

  • word in search consist of '.' or lowercase English letters.

  • There will be at most 2 dots in word for search queries.

  • At most 104 calls will be made to addWord and search.

Deep-Dive & Conceptual Insights

Core Insight

A Trie with recursive branching evaluates wildcard queries in optimal prefix-constrained time.

Real-World Scenario & Production Applications

Regular expression matching engines, dictionary crossword wildcard lookups.

Step-by-Step Execution Trace Table

Char in QueryTrie ActionSubtrees ExploredMatch?
'.'Branch across all children'b' and 'd' branches-
'a'Follow 'a' child'ba' and 'da'-
'd'Check terminal '$''bad' ()and′dad′() and 'dad' ()and′dad′()True
Code Shape
Archetype Code Shape
Python
1def addWord(word):
2 insert word into the trie, as in a standard trie
3def search(word):
4 def dfs(j, node):
5 for each character c of word from index j on:
6 if c == '.':
7 return True if dfs from the next index succeeds for any child
8 if c not in node:
9 return False
10 node = node[c]
11 return '$' in node

Conceptual Narrative

Standard Trie search follows a single deterministic hallway per letter. The wildcard '.' transforms search into a non-deterministic parallel exploration of all 26 branches simultaneously.

🧭 Conceptual Foundation & Pattern Intuition

In a standard Trie, each character corresponds to at most one child node (O(1)O(1)O(1) descent). In WordDictionary (LC 211), the query pattern may contain wildcards '.', where '.' matches any lowercase English letter. When the search encounters a literal character ('a'-'z'), it executes standard deterministic descent. When it encounters '.', determinism breaks: the algorithm must branch into a recursive DFS across all currently allocated child nodes at that level. If any child path returns True, the search immediately short-circuits and returns True. Worst-case complexity for a word of all dots "..." is O(26L)O(26^L)O(26L) in a dense Trie, but real-world dictionaries are sparse: words diverge, dead ends abort instantly, and search depth is strictly bounded by word length LLL.

🗝️ The Analogy: The Skeleton Key in a Corridor of 26 Doors

Imagine searching an office building for a specific employee. A literal letter 'b' means you must open the door labeled 'b'. But a wildcard '.' is a skeleton key that can open any door in the hallway. When you hold a skeleton key, you continue the search behind every door in the corridor, one door after another. As soon as the search behind one door finds the employee, you stop searching.

🔑 Why It Works

By splicing the string slice word[i + 1:] or passing an index pointer idx, literal characters cost O(1)O(1)O(1) descent while wildcards branch only across instantiated children, achieving optimal performance on sparse prefix trees.

  • Wildcard dot exponential branching without pruning: Branching into all 26 children on . without early pruning when no child nodes exist.

  • Overwriting is_end boolean on duplicate adds: Adding a word that already exists should preserve is_end = True.

  • Linear search fallback: Falling back to linear scan across all inserted words instead of recursive DFS down the Trie on wildcard . characters.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Prefix tree search with single-character wildcard '.' matching.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: wildcard '.' explores all existing child branches recursively.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Iterative search without stack on wildcard: '.' requires backtracking across multiple children.

  • Checking terminal '$' on intermediate non-word nodes.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I build a standard Trie using nested dictionaries. For search(word), I use helper dfs(j, node). If word[i] == '.', I recursively explore all child nodes in node.values(). Otherwise, I follow the exact character branch. At the end, I check if $ is in the terminal node. Runs in O(L) for normal search and O(26^L) worst-case wildcard time."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(L) Add, O(26^D · L) Search

Look at the execution steps: Adding word of length L takes O(L). Searching without dots takes O(L); wildcard '.' branches across at most 26 children (at depth D with D dots, takes O(26^D * L)).

SPACE COMPLEXITY

O(N · L · |Sigma|) Auxiliary

Look at memory allocations: Call stack uses O(L) Recursion depth during search. Trie storage holding N words of length L.

Formal Recurrence Relation

Tadd = O(L), Tsearch = O(26^D · L)

Derivation Progression

Exact Character Path

O(1) child lookup

Follows exact character edge in constant time.

Wildcard '.' Branching

26 recursive child searches

Recursively explores all 26 non-null child nodes for '.' wildcard.

Depth Bounding

O(26^D · L) where D = number of dots

Worst case when word consists entirely of '.' wildcards.

Variable Definitions

LLL

Length of the word or query

DDD

Number of wildcard '.' dots in search pattern

Memory Architecture & Bounds

🟣 Call Stack

O(L) Recursion depth during search

🔵 Auxiliary Heap

O(N · L · |Sigma|) TrieNode tree

🟢 Output Space

O(1) Boolean return

Boundary Best / Worst Cases

Best Case

O(L)O(L)O(L) when search has no wildcards.

Average Case

O(L)O(L)O(L).

Worst Case

O(26L)O(26^L)O(26L) for string of all '.' wildcards.

Recurrence Tree Topology

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

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "addWord", "search words with '.' matching any letter". Literal characters traverse a single Trie child, while the wildcard character '.' branches across all existing children. A Senior SWE applies Trie + Recursive Wildcard DFS Backtracking.

CONSTRAINTS & BOUNDS

Word length L≤25L \le 25L≤25, at most 2 dots per search query, up to 10410^4104 operations. At most 262×25≈1700026^2 \times 25 \approx 17000262×25≈17000 operations in the worst case.

FAANG PRODUCTION TRAPS & EDGE CASES

Base case termination: when i==len(word)i == len(word)i==len(word), return node.is_end. If the child path doesn't exist, return False immediately without unneeded calls.

Theory Context•Advanced Data Structures
MediumLC 211

Design Add and Search Words Data Structure (LeetCode 211)

Target Frequency:MetaAmazonGoogleApple

Build a structure that can remember a growing set of words and later test whether a query string matches any of them.

Implement a WordDictionary class:

  • WordDictionary() starts with an empty set of words.
  • void addWord(word) remembers word so later searches can match it.
  • bool search(word) returns true if some remembered word matches word, else false. In word, a . character stands in for any single letter.

Worked Examples

Example 1
Input:["WordDictionary","addWord","addWord","addWord","search","search","search","search"] [[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
Output:[null,null,null,null,false,true,true,true]
Explanation: "pad" was never added. "bad" was. ".ad" matches "bad", "dad" or "mad", and "b.." matches "bad".

⚖️Formal Constraints & Bounds

  • 1 <= word.length <= 25

  • word in addWord consists of lowercase English letters.

  • word in search consist of '.' or lowercase English letters.

  • There will be at most 2 dots in word for search queries.

  • At most 104 calls will be made to addWord and search.

Deep-Dive & Conceptual Insights

Core Insight

A Trie with recursive branching evaluates wildcard queries in optimal prefix-constrained time.

Real-World Scenario & Production Applications

Regular expression matching engines, dictionary crossword wildcard lookups.

Step-by-Step Execution Trace Table

Char in QueryTrie ActionSubtrees ExploredMatch?
'.'Branch across all children'b' and 'd' branches-
'a'Follow 'a' child'ba' and 'da'-
'd'Check terminal '$''bad' ()and′dad′() and 'dad' ()and′dad′()True
Code Shape
Archetype Code Shape
Python
1def addWord(word):
2 insert word into the trie, as in a standard trie
3def search(word):
4 def dfs(j, node):
5 for each character c of word from index j on:
6 if c == '.':
7 return True if dfs from the next index succeeds for any child
8 if c not in node:
9 return False
10 node = node[c]
11 return '$' in node

Conceptual Narrative

Standard Trie search follows a single deterministic hallway per letter. The wildcard '.' transforms search into a non-deterministic parallel exploration of all 26 branches simultaneously.

🧭 Conceptual Foundation & Pattern Intuition

In a standard Trie, each character corresponds to at most one child node (O(1)O(1)O(1) descent). In WordDictionary (LC 211), the query pattern may contain wildcards '.', where '.' matches any lowercase English letter. When the search encounters a literal character ('a'-'z'), it executes standard deterministic descent. When it encounters '.', determinism breaks: the algorithm must branch into a recursive DFS across all currently allocated child nodes at that level. If any child path returns True, the search immediately short-circuits and returns True. Worst-case complexity for a word of all dots "..." is O(26L)O(26^L)O(26L) in a dense Trie, but real-world dictionaries are sparse: words diverge, dead ends abort instantly, and search depth is strictly bounded by word length LLL.

🗝️ The Analogy: The Skeleton Key in a Corridor of 26 Doors

Imagine searching an office building for a specific employee. A literal letter 'b' means you must open the door labeled 'b'. But a wildcard '.' is a skeleton key that can open any door in the hallway. When you hold a skeleton key, you continue the search behind every door in the corridor, one door after another. As soon as the search behind one door finds the employee, you stop searching.

🔑 Why It Works

By splicing the string slice word[i + 1:] or passing an index pointer idx, literal characters cost O(1)O(1)O(1) descent while wildcards branch only across instantiated children, achieving optimal performance on sparse prefix trees.

  • Wildcard dot exponential branching without pruning: Branching into all 26 children on . without early pruning when no child nodes exist.

  • Overwriting is_end boolean on duplicate adds: Adding a word that already exists should preserve is_end = True.

  • Linear search fallback: Falling back to linear scan across all inserted words instead of recursive DFS down the Trie on wildcard . characters.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Prefix tree search with single-character wildcard '.' matching.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: wildcard '.' explores all existing child branches recursively.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Iterative search without stack on wildcard: '.' requires backtracking across multiple children.

  • Checking terminal '$' on intermediate non-word nodes.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I build a standard Trie using nested dictionaries. For search(word), I use helper dfs(j, node). If word[i] == '.', I recursively explore all child nodes in node.values(). Otherwise, I follow the exact character branch. At the end, I check if $ is in the terminal node. Runs in O(L) for normal search and O(26^L) worst-case wildcard time."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(L) Add, O(26^D · L) Search

Look at the execution steps: Adding word of length L takes O(L). Searching without dots takes O(L); wildcard '.' branches across at most 26 children (at depth D with D dots, takes O(26^D * L)).

SPACE COMPLEXITY

O(N · L · |Sigma|) Auxiliary

Look at memory allocations: Call stack uses O(L) Recursion depth during search. Trie storage holding N words of length L.

Formal Recurrence Relation

Tadd = O(L), Tsearch = O(26^D · L)

Derivation Progression

Exact Character Path

O(1) child lookup

Follows exact character edge in constant time.

Wildcard '.' Branching

26 recursive child searches

Recursively explores all 26 non-null child nodes for '.' wildcard.

Depth Bounding

O(26^D · L) where D = number of dots

Worst case when word consists entirely of '.' wildcards.

Variable Definitions

LLL

Length of the word or query

DDD

Number of wildcard '.' dots in search pattern

Memory Architecture & Bounds

🟣 Call Stack

O(L) Recursion depth during search

🔵 Auxiliary Heap

O(N · L · |Sigma|) TrieNode tree

🟢 Output Space

O(1) Boolean return

Boundary Best / Worst Cases

Best Case

O(L)O(L)O(L) when search has no wildcards.

Average Case

O(L)O(L)O(L).

Worst Case

O(26L)O(26^L)O(26L) for string of all '.' wildcards.

Recurrence Tree Topology

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

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "addWord", "search words with '.' matching any letter". Literal characters traverse a single Trie child, while the wildcard character '.' branches across all existing children. A Senior SWE applies Trie + Recursive Wildcard DFS Backtracking.

CONSTRAINTS & BOUNDS

Word length L≤25L \le 25L≤25, at most 2 dots per search query, up to 10410^4104 operations. At most 262×25≈1700026^2 \times 25 \approx 17000262×25≈17000 operations in the worst case.

FAANG PRODUCTION TRAPS & EDGE CASES

Base case termination: when i==len(word)i == len(word)i==len(word), return node.is_end. If the child path doesn't exist, return False immediately without unneeded calls.

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