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•Two Pointers & Sliding Window
HardLC 76

Minimum Window Substring (LeetCode 76)

Target Frequency:MetaGoogleAmazonNetflix

You have two strings, s (length m) and t (length n). Find the shortest contiguous slice of s that contains every character of t, counting repeated characters as many times as they occur in t. If no slice of s qualifies, return the empty string "".

The test cases are built so that whenever an answer exists, it's unique.

Worked Examples

Example 1
Input:s = "ADOBECODEBANC", t = "ABC"
Output:"BANC"
Explanation: "BANC" is the shortest slice of s that still covers every character of t ('A', 'B', and 'C').
Example 2
Input:s = "a", t = "a"
Output:"a"
Explanation: The entire string s is the minimum window.
Example 3
Input:s = "a", t = "aa"
Output:""
Explanation: t needs two 'a's covered, but s only has one 'a' total, so no window of s can ever satisfy t; the answer is the empty string.

⚖️Formal Constraints & Bounds

  • m == s.length

  • n == t.length

  • 1 <= m, n <= 105

  • s and t consist of uppercase and lowercase English letters.

Deep-Dive & Conceptual Insights

Core Insight

Tracking satisfied distinct character counts allows O(1) validity checking during window contractions.

Real-World Scenario & Production Applications

Full-text search highlighting (showing minimal context snippet containing all query terms), compiler syntax chunking.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Target Frequency Mapping

Build character frequency map need from string t. Maintain have = 0 and required = len(need) to track fulfilled unique character requirements.

Mathematical Recurrence / Code Invariant
need = Counter(t)
required = len(need)
have = 0
window = {}

Step-by-Step Execution Trace Table

right charWindowmatchedActionBest Window
'A'..'C' (idx 5)"ADOBEC"3 / 3 (All matched)Contract left past 'A'"ADOBEC" (len 6)
'O'..'C' (idx 10)"CODEBA"3 / 3 (All matched)Contract left"ODEBANC"
'N'..'C' (idx 12)"BANC"3 / 3 (All matched)Contract left"BANC" (len 4)
Code Shape
Archetype Code Shape
Python
1need = Counter(t)
2have = {}
3matched = 0
4res = (inf, 0, 0)
5left = 0
6for right in range(len(s)):
7 c = s[right]
8 have[c] = have.get(c, 0) + 1
9 if c in need and have[c] == need[c]:
10 matched += 1
11 while matched == len(need):
12 record the window if it is the shortest so far
13 remove s[left] from have (matched -= 1 if its count falls below need)
14 left += 1
15return best_substring

Conceptual Narrative

A harder Sliding Window problem: the window tracks the count of every required character and shrinks whenever it can.

🧭 Conceptual Foundation & Pattern Intuition

In basic sliding window problems (like LC 209 or LC 3), the condition to expand or shrink depends on a scalar sum or a simple set of unique characters. In Minimum Window Substring (LC 76), the window must contain every character from string t with at least the frequency specified in t.

Checking whether the current window contains all required frequencies naively takes O(∣Σ∣)O(|\Sigma|)O(∣Σ∣) time on every step. Over a string of length NNN, that would degrade performance to O(∣Σ∣⋅N)O(|\Sigma| \cdot N)O(∣Σ∣⋅N). The algorithmic breakthrough is Dual-State Frequency Tracking:

  1. A frequency map need storing required counts for each character in t.
  2. A running frequency map have for characters in the active window.
  3. A scalar counter matched: tracks how many unique characters in t have reached their required frequency threshold (have[c] == need[c]).

When matched == len(need), the window is unconditionally valid! You record the candidate length and greedily contract from the left to find the tightest possible valid substring.

🛒 The Analogy: The Grocery Shopping Checklist

Imagine you have a shopping list (t): you need 3 Apples, 2 Bananas, and 1 Carrot. You walk down a superstore aisle (s) tossing produce into your cart (right pointer):

  • When you pick up your 3rd Apple, you cross "Apples" off your checklist (matched += 1).
  • Picking up a 4th Apple doesn't check off any new item—it's just a surplus.
  • Once every item on your checklist is crossed off (matched == len(need)), your cart is valid!
  • Now, can you trim items from the start of your aisle run (left pointer) to make your shopping trip as short as possible? You put items back onto shelves from the front. If you put back an orange (not on list) or a surplus apple (still leaving 3 in cart), your checklist is still complete! Only when you put back an essential item so its count falls below the required threshold (have[c] < need[c]) do you uncheck that item (matched -= 1) and resume walking forward.
🔑 The Key Idea in the Code

Because each character is visited at most twice (once by right, once by left), the entire algorithm executes in strict O(∣s∣+∣t∣)O(|s| + |t|)O(∣s∣+∣t∣) linear time.

  • Comparing character count dictionaries on each step: Comparing frequency maps of size 128 takes O(128) per iteration. Use a matched count of unique characters to achieve strict O(1) step transitions.

  • Prematurely decrementing matched count: When shrinking left, only decrement matched -= 1 when window[char] < target[char]. If window[char] was exceeding target[char], removing it does not break validity.

  • Off-by-one in substring slice: When storing the best window [start, min_len], the return slice in Python is s[start : start + min_len], not s[start : min_len].

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Shortest substring containing all characters of a target string with character multiplicity.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: matched counter increments only when have[c] == need[c]; window is valid when matched == len(need).

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Forgetting to decrement matched when an evicted character count drops below need.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I count required character frequencies in t and use a matched scalar counter. I expand right adding characters to have; when have[c] reaches need[c], matched increments. When matched == len(need), I shrink left, recording the minimum window. Runs in O(N) time and O(1) auxiliary space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N + M)

Look at the execution steps: Counts target characters in T (length M). Right pointer expands over S (length N) satisfying required character counts; left contracts window while still valid. Total 2N pointer advances.

SPACE COMPLEXITY

O(|Sigma|) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Frequency maps for target characters and active window bounded by character set size Sigma.

Formal Recurrence Relation

T(N, M) = O(M) + O(2N) = O(N + M)

Derivation Progression

Target Frequency Count

O(M) over string T

Builds frequency map of required characters in T of length M.

Right Window Expansion

R advances N times

Adds characters to window map and increments formed counter when count matches requirement.

Left Contraction & Result Capture

L advances at most N times

Shrinks window from left while maintaining formed == required condition, updating shortest valid window.

Variable Definitions

NNN

Length of source string s

MMM

Length of target string t

∣Σ∣|Σ|∣Σ∣

Character set size (at most 128 ASCII characters)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(|Sigma|) Two character frequency tables (at most 128 ASCII entries)

🟢 Output Space

O(K) Substring slice where K <= N

Boundary Best / Worst Cases

Best Case

O(N+M)O(N + M)O(N+M)

Average Case

O(N+M)O(N + M)O(N+M)

Worst Case

O(N+M)O(N + M)O(N+M)

Pointer Invariant Transition Progression

Pointer Invariant Transition Progression
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "smallest substring covering every character of t, duplicates and all". Variable sliding window with multiset coverage tracking.

CONSTRAINTS & BOUNDS

1≤∣s∣,∣t∣≤1051 \le |s|, |t| \le 10^51≤∣s∣,∣t∣≤105. Time budget strictly linear O(∣s∣+∣t∣)O(|s| + |t|)O(∣s∣+∣t∣). Space O(∣Σ∣)O(|\Sigma|)O(∣Σ∣).

FAANG PRODUCTION TRAPS & EDGE CASES

Duplicate character matching: increment have only when window_freq[c] == t_freq[c], not on every occurrence. Decrement have only when window_freq[c] < t_freq[c] during contraction. No valid window exists (return "").

Theory Context•Two Pointers & Sliding Window
HardLC 76

Minimum Window Substring (LeetCode 76)

Target Frequency:MetaGoogleAmazonNetflix

You have two strings, s (length m) and t (length n). Find the shortest contiguous slice of s that contains every character of t, counting repeated characters as many times as they occur in t. If no slice of s qualifies, return the empty string "".

The test cases are built so that whenever an answer exists, it's unique.

Worked Examples

Example 1
Input:s = "ADOBECODEBANC", t = "ABC"
Output:"BANC"
Explanation: "BANC" is the shortest slice of s that still covers every character of t ('A', 'B', and 'C').
Example 2
Input:s = "a", t = "a"
Output:"a"
Explanation: The entire string s is the minimum window.
Example 3
Input:s = "a", t = "aa"
Output:""
Explanation: t needs two 'a's covered, but s only has one 'a' total, so no window of s can ever satisfy t; the answer is the empty string.

⚖️Formal Constraints & Bounds

  • m == s.length

  • n == t.length

  • 1 <= m, n <= 105

  • s and t consist of uppercase and lowercase English letters.

Deep-Dive & Conceptual Insights

Core Insight

Tracking satisfied distinct character counts allows O(1) validity checking during window contractions.

Real-World Scenario & Production Applications

Full-text search highlighting (showing minimal context snippet containing all query terms), compiler syntax chunking.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Target Frequency Mapping

Build character frequency map need from string t. Maintain have = 0 and required = len(need) to track fulfilled unique character requirements.

Mathematical Recurrence / Code Invariant
need = Counter(t)
required = len(need)
have = 0
window = {}

Step-by-Step Execution Trace Table

right charWindowmatchedActionBest Window
'A'..'C' (idx 5)"ADOBEC"3 / 3 (All matched)Contract left past 'A'"ADOBEC" (len 6)
'O'..'C' (idx 10)"CODEBA"3 / 3 (All matched)Contract left"ODEBANC"
'N'..'C' (idx 12)"BANC"3 / 3 (All matched)Contract left"BANC" (len 4)
Code Shape
Archetype Code Shape
Python
1need = Counter(t)
2have = {}
3matched = 0
4res = (inf, 0, 0)
5left = 0
6for right in range(len(s)):
7 c = s[right]
8 have[c] = have.get(c, 0) + 1
9 if c in need and have[c] == need[c]:
10 matched += 1
11 while matched == len(need):
12 record the window if it is the shortest so far
13 remove s[left] from have (matched -= 1 if its count falls below need)
14 left += 1
15return best_substring

Conceptual Narrative

A harder Sliding Window problem: the window tracks the count of every required character and shrinks whenever it can.

🧭 Conceptual Foundation & Pattern Intuition

In basic sliding window problems (like LC 209 or LC 3), the condition to expand or shrink depends on a scalar sum or a simple set of unique characters. In Minimum Window Substring (LC 76), the window must contain every character from string t with at least the frequency specified in t.

Checking whether the current window contains all required frequencies naively takes O(∣Σ∣)O(|\Sigma|)O(∣Σ∣) time on every step. Over a string of length NNN, that would degrade performance to O(∣Σ∣⋅N)O(|\Sigma| \cdot N)O(∣Σ∣⋅N). The algorithmic breakthrough is Dual-State Frequency Tracking:

  1. A frequency map need storing required counts for each character in t.
  2. A running frequency map have for characters in the active window.
  3. A scalar counter matched: tracks how many unique characters in t have reached their required frequency threshold (have[c] == need[c]).

When matched == len(need), the window is unconditionally valid! You record the candidate length and greedily contract from the left to find the tightest possible valid substring.

🛒 The Analogy: The Grocery Shopping Checklist

Imagine you have a shopping list (t): you need 3 Apples, 2 Bananas, and 1 Carrot. You walk down a superstore aisle (s) tossing produce into your cart (right pointer):

  • When you pick up your 3rd Apple, you cross "Apples" off your checklist (matched += 1).
  • Picking up a 4th Apple doesn't check off any new item—it's just a surplus.
  • Once every item on your checklist is crossed off (matched == len(need)), your cart is valid!
  • Now, can you trim items from the start of your aisle run (left pointer) to make your shopping trip as short as possible? You put items back onto shelves from the front. If you put back an orange (not on list) or a surplus apple (still leaving 3 in cart), your checklist is still complete! Only when you put back an essential item so its count falls below the required threshold (have[c] < need[c]) do you uncheck that item (matched -= 1) and resume walking forward.
🔑 The Key Idea in the Code

Because each character is visited at most twice (once by right, once by left), the entire algorithm executes in strict O(∣s∣+∣t∣)O(|s| + |t|)O(∣s∣+∣t∣) linear time.

  • Comparing character count dictionaries on each step: Comparing frequency maps of size 128 takes O(128) per iteration. Use a matched count of unique characters to achieve strict O(1) step transitions.

  • Prematurely decrementing matched count: When shrinking left, only decrement matched -= 1 when window[char] < target[char]. If window[char] was exceeding target[char], removing it does not break validity.

  • Off-by-one in substring slice: When storing the best window [start, min_len], the return slice in Python is s[start : start + min_len], not s[start : min_len].

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Shortest substring containing all characters of a target string with character multiplicity.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: matched counter increments only when have[c] == need[c]; window is valid when matched == len(need).

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Forgetting to decrement matched when an evicted character count drops below need.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I count required character frequencies in t and use a matched scalar counter. I expand right adding characters to have; when have[c] reaches need[c], matched increments. When matched == len(need), I shrink left, recording the minimum window. Runs in O(N) time and O(1) auxiliary space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N + M)

Look at the execution steps: Counts target characters in T (length M). Right pointer expands over S (length N) satisfying required character counts; left contracts window while still valid. Total 2N pointer advances.

SPACE COMPLEXITY

O(|Sigma|) Auxiliary

Look at memory allocations: Call stack uses O(1) Iterative. Frequency maps for target characters and active window bounded by character set size Sigma.

Formal Recurrence Relation

T(N, M) = O(M) + O(2N) = O(N + M)

Derivation Progression

Target Frequency Count

O(M) over string T

Builds frequency map of required characters in T of length M.

Right Window Expansion

R advances N times

Adds characters to window map and increments formed counter when count matches requirement.

Left Contraction & Result Capture

L advances at most N times

Shrinks window from left while maintaining formed == required condition, updating shortest valid window.

Variable Definitions

NNN

Length of source string s

MMM

Length of target string t

∣Σ∣|Σ|∣Σ∣

Character set size (at most 128 ASCII characters)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative

🔵 Auxiliary Heap

O(|Sigma|) Two character frequency tables (at most 128 ASCII entries)

🟢 Output Space

O(K) Substring slice where K <= N

Boundary Best / Worst Cases

Best Case

O(N+M)O(N + M)O(N+M)

Average Case

O(N+M)O(N + M)O(N+M)

Worst Case

O(N+M)O(N + M)O(N+M)

Pointer Invariant Transition Progression

Pointer Invariant Transition Progression
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "smallest substring covering every character of t, duplicates and all". Variable sliding window with multiset coverage tracking.

CONSTRAINTS & BOUNDS

1≤∣s∣,∣t∣≤1051 \le |s|, |t| \le 10^51≤∣s∣,∣t∣≤105. Time budget strictly linear O(∣s∣+∣t∣)O(|s| + |t|)O(∣s∣+∣t∣). Space O(∣Σ∣)O(|\Sigma|)O(∣Σ∣).

FAANG PRODUCTION TRAPS & EDGE CASES

Duplicate character matching: increment have only when window_freq[c] == t_freq[c], not on every occurrence. Decrement have only when window_freq[c] < t_freq[c] during contraction. No valid window exists (return "").

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