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

Longest Substring Without Repeating Characters (LeetCode 3)

Target Frequency:AmazonGoogleMetaAppleNetflix

You have a string s. Among all of its contiguous substrings, find the longest one that never repeats a character, and report its length.

Worked Examples

Example 1
Input:s = "abcabcbb"
Output:3
Explanation: "abc" is a repeat-free run of length 3; "bca" and "cab" would also be valid answers of the same length.
Example 2
Input:s = "bbbbb"
Output:1
Explanation: Every character is 'b', so the longest repeat-free run is just "b", length 1.
Example 3
Input:s = "pwwkew"
Output:3
Explanation: "wke" is the longest repeat-free run, length 3. "pwke" is not valid here since it skips over the 'w' at index 2, making it a subsequence rather than a contiguous substring.

⚖️Formal Constraints & Bounds

  • 0 <= s.length <= 105

  • s consists of English letters, digits, symbols and spaces.

Deep-Dive & Conceptual Insights

Core Insight

Maintaining a hash set of characters currently in the window allows O(1) duplicate checks and amortized O(N) window repairs.

Real-World Scenario & Production Applications

Tokenization parsers, compression algorithms (LZW dictionary windows), and network session deduplication caches.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Right Expansion & Last-Seen Indexing

Iterate right from 0 to N-1. Maintain a hash map char_map storing the latest index where each character was observed.

Mathematical Recurrence / Code Invariant
char_map = {}  # char -> latest seen index
left = 0
max_len = 0

Step-by-Step Execution Trace Table

StepActionwindowleftmax_len
1add a (right=0)a01
2add b (right=1)ab02
3add c (right=2)abc03
4right=3 is a — duplicate →\to→ drop s[0]='a'bc13
5window legal →\to→ add abca13
6right=4 is b — duplicate →\to→ drop s[1]='b'ca23
7window legal →\to→ add bcab23
8right=5 is c — duplicate →\to→ drop s[2]='c'ab33
9window legal →\to→ add cabc33
10right=6 is b — duplicate →\to→ drop s[3]='a'bc43
11still duplicate →\to→ drop s[4]='b'c53
12window legal →\to→ add bcb53
13right=7 is b — duplicate →\to→ drop s[5]='c'b63
14still duplicate →\to→ drop s[6]='b'(empty)73
15window legal →\to→ add bb73 (Search complete)
Code Shape
Archetype Code Shape
Python
1seen_chars = set()
2left = 0
3max_len = 0
4for right in range(len(s)):
5 while s[right] in seen_chars:
6 seen_chars.remove(s[left])
7 left += 1
8 seen_chars.add(s[right])
9 max_len = max(max_len, right - left + 1)
10return max_len

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

This is the pattern's first growing window — both edges now move independently, and the shrink direction is triggered by a violation instead of a fixed size.

📸 The Analogy: A Photo Frame That Only Shrinks When It Has To

Picture a camera frame sliding across a sentence, always trying to grow as wide as possible while keeping "no repeated letter visible" true. You keep sliding the right edge outward, capturing one more letter each time — as long as that letter isn't already inside the frame. The moment it would create a duplicate, you don't restart from scratch; you just nudge the left edge of the frame inward, one letter at a time, only far enough to evict the earlier copy of that duplicate letter. Then you keep growing right again.

🔑 The Key Idea in the Code

The frame never resets to empty and restarts — it only ever shrinks by the minimum amount needed to repair the violation, which is what keeps this an O(N) pass instead of an O(N²) restart-from-scratch scan.

  • Recording answer inside the duplicate loop: In longest-window problems (LC 3), the window is valid AFTER the duplicate character has been removed. Record max_len = max(max_len, right - left + 1) after the inner while loop, not inside it.

  • Evicting wrong character from set: When duplicate s[right] is found, you must remove s[left] from the set and increment left += 1 until s[right] is no longer in set, not remove s[right] directly.

  • Stale index lookup with character map: If storing {char: last_seen_index}, jumping left = map[char] + 1 is only valid if map[char] >= left. Forgetting max(left, map[char] + 1) moves left backwards!

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"the longest one that never repeats a character" among contiguous substrings: the longest window that stays valid under a no-repeat rule (Longest Window).

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: after the repair loop, seen_chars is exactly the set of characters in s[left..right], with no repeats.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Measuring too early: update max_len only after the while loop; before it, the window may still hold the repeat.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use a Longest Window. I move right one character at a time and keep seen_chars equal to the characters between left and right. If s[right] is already in seen_chars, the window holds a repeat, so I remove s[left] and move left forward until the old copy is gone. That loses nothing: any window that ends at right and starts before the new left still holds the repeat. Then I add s[right] and record right - left + 1 in max_len. The trap is measuring too early: I update max_len only after the repair loop, because before it the window can still hold a duplicate. On bbbbb, measuring before the repair gives 2 instead of 1. Each character is added once and removed at most once, so it's O(N) time, with O(min(N, alphabet)) space for the set."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the loops: for right in range(len(s)): runs N times and adds s[right] to seen_chars once each time. The inner while s[right] in seen_chars: removes s[left] and moves left forward; a character can only be removed after it was added, so across the whole run there are at most N removals. Set membership, add and remove are O(1) on average, so the total is N + N = O(N).

SPACE COMPLEXITY

O(min(N, Sigma))

Look at memory allocation: The call stack is iterative O(1). seen_chars holds only distinct characters of the current window, so at most min(N, Sigma) of them (at most 128 for ASCII).

Formal Recurrence Relation

N additions + at most N removals = O(N)

Derivation Progression

Right Pointer Window Scan

N iterations

The outer loop adds each character of s to seen_chars exactly once.

Amortized Repair

at most N removals in total

left only moves forward, and each move removes one character that was added earlier.

Linear Convergence

N + N = O(N)

Every character enters and leaves the window at most once.

Variable Definitions

NNN

Total length of the string

SigmaSigmaSigma

Character set size (at most 128 ASCII characters)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative loop with zero recursion frames

🔵 Auxiliary Heap

O(min(N, Sigma)) The set seen_chars

🟢 Output Space

O(1) Returns max length 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)

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: "longest substring without repeating characters". Monotonic sliding window: before right is added, check whether adding it would break the rule; if it would, shrink/jump left to repair first, then add right.

CONSTRAINTS & BOUNDS

0≤N≤1050 \le N \le 10^50≤N≤105. Time budget strictly O(N)O(N)O(N), space O(min⁡(N,∣Σ∣))O(\min(N, |\Sigma|))O(min(N,∣Σ∣)). On a long stream the set never holds more than the alphabet, so memory stays bounded however long the input is.

FAANG PRODUCTION TRAPS & EDGE CASES

An empty string needs no special case: the loop never runs and max_len stays 0. If you jump left with an index map instead of a set, use left = max(left, last_seen[ch] + 1): in "abba" the second 'a' was last seen before left, and a plain jump would move left backwards.

Theory Context•Two Pointers & Sliding Window
MediumLC 3

Longest Substring Without Repeating Characters (LeetCode 3)

Target Frequency:AmazonGoogleMetaAppleNetflix

You have a string s. Among all of its contiguous substrings, find the longest one that never repeats a character, and report its length.

Worked Examples

Example 1
Input:s = "abcabcbb"
Output:3
Explanation: "abc" is a repeat-free run of length 3; "bca" and "cab" would also be valid answers of the same length.
Example 2
Input:s = "bbbbb"
Output:1
Explanation: Every character is 'b', so the longest repeat-free run is just "b", length 1.
Example 3
Input:s = "pwwkew"
Output:3
Explanation: "wke" is the longest repeat-free run, length 3. "pwke" is not valid here since it skips over the 'w' at index 2, making it a subsequence rather than a contiguous substring.

⚖️Formal Constraints & Bounds

  • 0 <= s.length <= 105

  • s consists of English letters, digits, symbols and spaces.

Deep-Dive & Conceptual Insights

Core Insight

Maintaining a hash set of characters currently in the window allows O(1) duplicate checks and amortized O(N) window repairs.

Real-World Scenario & Production Applications

Tokenization parsers, compression algorithms (LZW dictionary windows), and network session deduplication caches.

Subproblems & Recurrence Decomposition3 Phases

🧩Subproblem 1: Right Expansion & Last-Seen Indexing

Iterate right from 0 to N-1. Maintain a hash map char_map storing the latest index where each character was observed.

Mathematical Recurrence / Code Invariant
char_map = {}  # char -> latest seen index
left = 0
max_len = 0

Step-by-Step Execution Trace Table

StepActionwindowleftmax_len
1add a (right=0)a01
2add b (right=1)ab02
3add c (right=2)abc03
4right=3 is a — duplicate →\to→ drop s[0]='a'bc13
5window legal →\to→ add abca13
6right=4 is b — duplicate →\to→ drop s[1]='b'ca23
7window legal →\to→ add bcab23
8right=5 is c — duplicate →\to→ drop s[2]='c'ab33
9window legal →\to→ add cabc33
10right=6 is b — duplicate →\to→ drop s[3]='a'bc43
11still duplicate →\to→ drop s[4]='b'c53
12window legal →\to→ add bcb53
13right=7 is b — duplicate →\to→ drop s[5]='c'b63
14still duplicate →\to→ drop s[6]='b'(empty)73
15window legal →\to→ add bb73 (Search complete)
Code Shape
Archetype Code Shape
Python
1seen_chars = set()
2left = 0
3max_len = 0
4for right in range(len(s)):
5 while s[right] in seen_chars:
6 seen_chars.remove(s[left])
7 left += 1
8 seen_chars.add(s[right])
9 max_len = max(max_len, right - left + 1)
10return max_len

Conceptual Narrative

🧭 Conceptual Foundation & Pattern Intuition

This is the pattern's first growing window — both edges now move independently, and the shrink direction is triggered by a violation instead of a fixed size.

📸 The Analogy: A Photo Frame That Only Shrinks When It Has To

Picture a camera frame sliding across a sentence, always trying to grow as wide as possible while keeping "no repeated letter visible" true. You keep sliding the right edge outward, capturing one more letter each time — as long as that letter isn't already inside the frame. The moment it would create a duplicate, you don't restart from scratch; you just nudge the left edge of the frame inward, one letter at a time, only far enough to evict the earlier copy of that duplicate letter. Then you keep growing right again.

🔑 The Key Idea in the Code

The frame never resets to empty and restarts — it only ever shrinks by the minimum amount needed to repair the violation, which is what keeps this an O(N) pass instead of an O(N²) restart-from-scratch scan.

  • Recording answer inside the duplicate loop: In longest-window problems (LC 3), the window is valid AFTER the duplicate character has been removed. Record max_len = max(max_len, right - left + 1) after the inner while loop, not inside it.

  • Evicting wrong character from set: When duplicate s[right] is found, you must remove s[left] from the set and increment left += 1 until s[right] is no longer in set, not remove s[right] directly.

  • Stale index lookup with character map: If storing {char: last_seen_index}, jumping left = map[char] + 1 is only valid if map[char] >= left. Forgetting max(left, map[char] + 1) moves left backwards!

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

"the longest one that never repeats a character" among contiguous substrings: the longest window that stays valid under a no-repeat rule (Longest Window).

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: after the repair loop, seen_chars is exactly the set of characters in s[left..right], with no repeats.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

  • Measuring too early: update max_len only after the while loop; before it, the window may still hold the repeat.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I'd use a Longest Window. I move right one character at a time and keep seen_chars equal to the characters between left and right. If s[right] is already in seen_chars, the window holds a repeat, so I remove s[left] and move left forward until the old copy is gone. That loses nothing: any window that ends at right and starts before the new left still holds the repeat. Then I add s[right] and record right - left + 1 in max_len. The trap is measuring too early: I update max_len only after the repair loop, because before it the window can still hold a duplicate. On bbbbb, measuring before the repair gives 2 instead of 1. Each character is added once and removed at most once, so it's O(N) time, with O(min(N, alphabet)) space for the set."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(N)

Look at the loops: for right in range(len(s)): runs N times and adds s[right] to seen_chars once each time. The inner while s[right] in seen_chars: removes s[left] and moves left forward; a character can only be removed after it was added, so across the whole run there are at most N removals. Set membership, add and remove are O(1) on average, so the total is N + N = O(N).

SPACE COMPLEXITY

O(min(N, Sigma))

Look at memory allocation: The call stack is iterative O(1). seen_chars holds only distinct characters of the current window, so at most min(N, Sigma) of them (at most 128 for ASCII).

Formal Recurrence Relation

N additions + at most N removals = O(N)

Derivation Progression

Right Pointer Window Scan

N iterations

The outer loop adds each character of s to seen_chars exactly once.

Amortized Repair

at most N removals in total

left only moves forward, and each move removes one character that was added earlier.

Linear Convergence

N + N = O(N)

Every character enters and leaves the window at most once.

Variable Definitions

NNN

Total length of the string

SigmaSigmaSigma

Character set size (at most 128 ASCII characters)

Memory Architecture & Bounds

🟣 Call Stack

O(1) Iterative loop with zero recursion frames

🔵 Auxiliary Heap

O(min(N, Sigma)) The set seen_chars

🟢 Output Space

O(1) Returns max length 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)

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: "longest substring without repeating characters". Monotonic sliding window: before right is added, check whether adding it would break the rule; if it would, shrink/jump left to repair first, then add right.

CONSTRAINTS & BOUNDS

0≤N≤1050 \le N \le 10^50≤N≤105. Time budget strictly O(N)O(N)O(N), space O(min⁡(N,∣Σ∣))O(\min(N, |\Sigma|))O(min(N,∣Σ∣)). On a long stream the set never holds more than the alphabet, so memory stays bounded however long the input is.

FAANG PRODUCTION TRAPS & EDGE CASES

An empty string needs no special case: the loop never runs and max_len stays 0. If you jump left with an index map instead of a set, use left = max(left, last_seen[ch] + 1): in "abba" the second 'a' was last seen before left, and a plain jump would move left backwards.

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