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•Graph Algorithms
EasyLC 733

Flood Fill (LeetCode 733)

Target Frequency:MetaAppleAmazon

A pixel grid image, sized m x n, holds a color per cell image[i][j]. You also get a starting position (sr, sc) and a replacement color. Simulate a flood fill (the paint-bucket tool) starting there:

  • Recolor the starting pixel to color.
  • Recolor every pixel reachable from it through a chain of up/down/left/right neighbors that all shared the starting pixel's original color.
  • Stop once no more same-colored neighbor is left to recolor.

Return the grid after the fill.

Worked Examples

Example 1
Input:image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
Output:[[2,2,2],[2,2,0],[2,0,1]]
111110101
Explanation: Starting at (1, 1) (color 1), the fill spreads to every 1-colored pixel reachable through up/down/left/right steps and repaints them all to 2. The pixel at (2, 2) keeps its original color 1, because it only touches the filled region diagonally, not horizontally or vertically.
Example 2
Input:image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
Output:[[0,0,0],[0,0,0]]
Explanation: The starting pixel's color is already 0, the same as the target color, so the fill has nothing to change.

⚖️Formal Constraints & Bounds

  • m == image.length

  • n == image[i].length

  • 1 <= m, n <= 50

  • 0 <= image[i][j], color < 216

  • 0 <= sr < m

  • 0 <= sc < n

Deep-Dive & Conceptual Insights

Core Insight

In-place mutation prevents re-visitation, traversing the connected component in O(R · C) time.

Real-World Scenario & Production Applications

Paint bucket tool in graphics editors, bucket fill algorithms in image processing pipelines.

Step-by-Step Execution Trace Table

Pixel (r, c)Current ColorActionNext Calls
(1, 1)1Repaint to 2(0,1), (2,1), (1,0), (1,2)
(0, 1)1Repaint to 2(0,0), (0,2)
(0, 0)1Repaint to 2None
(1, 2)0Color mismatch (0 != 1)Return
Trace Inputimage = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
Expected[[2,2,2],[2,2,0],[2,0,1]]
Pixel (r, c)Current ColorActionNext Calls
(1, 1)1Repaint to 2(0,1), (2,1), (1,0), (1,2)
(0, 1)1Repaint to 2(0,0), (0,2)
(0, 0)1Repaint to 2None
(1, 2)0Color mismatch (0 != 1)Return
Code Shape
Archetype Code Shape
Python
1orig_color = image[sr][sc]
2if orig_color == color:
3 return image
4def dfs(r, c):
5 if (r, c) is outside the image or image[r][c] != orig_color:
6 return
7 image[r][c] = color
8 call dfs on each of the 4 neighbors
9dfs(sr, sc)
10return image

Conceptual Narrative

Flood Fill performs connected-component traversal on a 2D grid, replacing all contiguous pixels of an initial color with a target replacement color.

🧭 Conceptual Foundation & Pattern Intuition

Starting from pixel (sr, sc) with color ColdC_{old}Cold​, flood fill visits all orthogonally adjacent pixels sharing color ColdC_{old}Cold​ and overwrites them with CnewC_{new}Cnew​. Traversal (DFS or BFS) treats the grid as an implicit graph with unit edges between identical neighboring colors.

🏟️ The Analogy: Paint Bucket Fill Tool

Clicking a pixel in Microsoft Paint with the Paint Bucket tool fills that pixel and all contiguous identical-color pixels with the new color until hitting different-color boundaries.

🔑 Why It Works

Checking image[sr][sc] == color upfront eliminates infinite recursion when the starting pixel already has the target color.

  • Infinite recursion on identical target color: When image[sr][sc] == color, DFS recurses infinitely because the pixel never changes color. Guard with if orig == color: return image.

  • Grid boundary condition errors: Forgetting boundary checks (0 <= r < m and 0 <= c < n) before array indexing causes IndexError.

  • Diagonal neighbor leakage: Problem allows orthogonal movements only (4-directional); accidentally including 8-directional diagonal movements corrupts fill regions.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Repaint contiguous region of identical values.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: image[r][c] is mutated directly to target color, preventing cycles.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

This problem's traps are in Common Pitfalls above.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I record original_color = image[sr][sc]. If original_color == color, I return immediately. Otherwise, I run DFS from (sr, sc) in 4 directions, mutating valid cells to color. Runs in O(R · C) time and O(R · C) call stack space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(M · N)

Look at the execution steps: DFS/BFS from start pixel (sr, sc). Replaces connected pixels matching initial color with new color. Every connected cell visited once.

SPACE COMPLEXITY

O(M · N) Auxiliary

Recursion stack reaches depth at most M · N in worst case.

Formal Recurrence Relation

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

Derivation Progression

Initial Color Comparison

if image[r][c] == origColor

Identifies valid candidate neighbors in O(1).

Direct Color Modification

image[r][c] = color

Modifies pixel and marks visited simultaneously.

Bounded Exploration

O(M · N) operations

Each pixel is recolored at most once.

Variable Definitions

MMM

Total number of rows in the image

NNN

Total number of columns in the image

Memory Architecture & Bounds

🟣 Call Stack

O(M · N) Call stack depth

🔵 Auxiliary Heap

O(1) In-place image mutation

🟢 Output Space

O(1) Image reference

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1) if image[sr][sc] == color.

Average Case

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

Worst Case

O(M⋅N)O(M · N)O(M⋅N) if entire grid is original color.

Graph & Tree Traversal Frontier

Graph & Tree Traversal Frontier
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "flood fill", "starting pixel (sr, sc)", "change color of all 4-directionally connected pixels". In-place DFS recoloring starting from seed coordinates.

CONSTRAINTS & BOUNDS

m,n≤50m, n \le 50m,n≤50. Time budget is O(MN)O(MN)O(MN) linear.

FAANG PRODUCTION TRAPS & EDGE CASES

Infinite Recursion Base Case Trap: If orig_color == color, recoloring produces identical values, causing infinite cycle recursion and stack overflow! Guard if orig_color == color: return image upfront.

Theory Context•Graph Algorithms
EasyLC 733

Flood Fill (LeetCode 733)

Target Frequency:MetaAppleAmazon

A pixel grid image, sized m x n, holds a color per cell image[i][j]. You also get a starting position (sr, sc) and a replacement color. Simulate a flood fill (the paint-bucket tool) starting there:

  • Recolor the starting pixel to color.
  • Recolor every pixel reachable from it through a chain of up/down/left/right neighbors that all shared the starting pixel's original color.
  • Stop once no more same-colored neighbor is left to recolor.

Return the grid after the fill.

Worked Examples

Example 1
Input:image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
Output:[[2,2,2],[2,2,0],[2,0,1]]
111110101
Explanation: Starting at (1, 1) (color 1), the fill spreads to every 1-colored pixel reachable through up/down/left/right steps and repaints them all to 2. The pixel at (2, 2) keeps its original color 1, because it only touches the filled region diagonally, not horizontally or vertically.
Example 2
Input:image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
Output:[[0,0,0],[0,0,0]]
Explanation: The starting pixel's color is already 0, the same as the target color, so the fill has nothing to change.

⚖️Formal Constraints & Bounds

  • m == image.length

  • n == image[i].length

  • 1 <= m, n <= 50

  • 0 <= image[i][j], color < 216

  • 0 <= sr < m

  • 0 <= sc < n

Deep-Dive & Conceptual Insights

Core Insight

In-place mutation prevents re-visitation, traversing the connected component in O(R · C) time.

Real-World Scenario & Production Applications

Paint bucket tool in graphics editors, bucket fill algorithms in image processing pipelines.

Step-by-Step Execution Trace Table

Pixel (r, c)Current ColorActionNext Calls
(1, 1)1Repaint to 2(0,1), (2,1), (1,0), (1,2)
(0, 1)1Repaint to 2(0,0), (0,2)
(0, 0)1Repaint to 2None
(1, 2)0Color mismatch (0 != 1)Return
Trace Inputimage = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
Expected[[2,2,2],[2,2,0],[2,0,1]]
Pixel (r, c)Current ColorActionNext Calls
(1, 1)1Repaint to 2(0,1), (2,1), (1,0), (1,2)
(0, 1)1Repaint to 2(0,0), (0,2)
(0, 0)1Repaint to 2None
(1, 2)0Color mismatch (0 != 1)Return
Code Shape
Archetype Code Shape
Python
1orig_color = image[sr][sc]
2if orig_color == color:
3 return image
4def dfs(r, c):
5 if (r, c) is outside the image or image[r][c] != orig_color:
6 return
7 image[r][c] = color
8 call dfs on each of the 4 neighbors
9dfs(sr, sc)
10return image

Conceptual Narrative

Flood Fill performs connected-component traversal on a 2D grid, replacing all contiguous pixels of an initial color with a target replacement color.

🧭 Conceptual Foundation & Pattern Intuition

Starting from pixel (sr, sc) with color ColdC_{old}Cold​, flood fill visits all orthogonally adjacent pixels sharing color ColdC_{old}Cold​ and overwrites them with CnewC_{new}Cnew​. Traversal (DFS or BFS) treats the grid as an implicit graph with unit edges between identical neighboring colors.

🏟️ The Analogy: Paint Bucket Fill Tool

Clicking a pixel in Microsoft Paint with the Paint Bucket tool fills that pixel and all contiguous identical-color pixels with the new color until hitting different-color boundaries.

🔑 Why It Works

Checking image[sr][sc] == color upfront eliminates infinite recursion when the starting pixel already has the target color.

  • Infinite recursion on identical target color: When image[sr][sc] == color, DFS recurses infinitely because the pixel never changes color. Guard with if orig == color: return image.

  • Grid boundary condition errors: Forgetting boundary checks (0 <= r < m and 0 <= c < n) before array indexing causes IndexError.

  • Diagonal neighbor leakage: Problem allows orthogonal movements only (4-directional); accidentally including 8-directional diagonal movements corrupts fill regions.

Senior SWE Reasoning Architecture

4-Phase Thought Process Model

Pattern Recognition Signals

The 10-second spot

Repaint contiguous region of identical values.

Formulating the Predicate & Invariants

Turning intuition into a boolean rule

Invariant: image[r][c] is mutated directly to target color, preventing cycles.

Silent Failure Traps & Edge Cases

Where confident candidates still lose points

This problem's traps are in Common Pitfalls above.

The 60-Second Interview Pitch

Say this out loud before you type a single line

"I record original_color = image[sr][sc]. If original_color == color, I return immediately. Otherwise, I run DFS from (sr, sc) in 4 directions, mutating valid cells to color. Runs in O(R · C) time and O(R · C) call stack space."

Big-O Invariant Derivation

Complexity & Mathematical Proof

TIME COMPLEXITY

O(M · N)

Look at the execution steps: DFS/BFS from start pixel (sr, sc). Replaces connected pixels matching initial color with new color. Every connected cell visited once.

SPACE COMPLEXITY

O(M · N) Auxiliary

Recursion stack reaches depth at most M · N in worst case.

Formal Recurrence Relation

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

Derivation Progression

Initial Color Comparison

if image[r][c] == origColor

Identifies valid candidate neighbors in O(1).

Direct Color Modification

image[r][c] = color

Modifies pixel and marks visited simultaneously.

Bounded Exploration

O(M · N) operations

Each pixel is recolored at most once.

Variable Definitions

MMM

Total number of rows in the image

NNN

Total number of columns in the image

Memory Architecture & Bounds

🟣 Call Stack

O(M · N) Call stack depth

🔵 Auxiliary Heap

O(1) In-place image mutation

🟢 Output Space

O(1) Image reference

Boundary Best / Worst Cases

Best Case

O(1)O(1)O(1) if image[sr][sc] == color.

Average Case

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

Worst Case

O(M⋅N)O(M · N)O(M⋅N) if entire grid is original color.

Graph & Tree Traversal Frontier

Graph & Tree Traversal Frontier
Synthesizing vector architecture diagram...
Staff+ Engineering Perspective

Senior SWE Deconstruction & Hardware Caveats

ARCHITECTURAL SIGNALS & INTERVIEW TRIGGERS

Triggers: "flood fill", "starting pixel (sr, sc)", "change color of all 4-directionally connected pixels". In-place DFS recoloring starting from seed coordinates.

CONSTRAINTS & BOUNDS

m,n≤50m, n \le 50m,n≤50. Time budget is O(MN)O(MN)O(MN) linear.

FAANG PRODUCTION TRAPS & EDGE CASES

Infinite Recursion Base Case Trap: If orig_color == color, recoloring produces identical values, causing infinite cycle recursion and stack overflow! Guard if orig_color == color: return image upfront.

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