Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Flood Fill Lab
Matrices
Problem shape
Beginner
0,0
0,1
0,2
0,3
1,0
1,1
1,2
1,3
2,0
2,1
2,2
2,3
Core idea
Starting from one cell, visit connected cells with the same value and recolor them.
Step 1 / 5
Problem shape
Matrices Beginner
Flood Fill
Welcome to the Flood Fill algorithm lab. Starting from one cell, visit connected cells with the same value and recolor them. Use it when: Use for image fill, island counting, and connected regions in grids. The time complexity is O(R*C), and the space complexity is O(R*C). The pseudocode is: dfs(r, c) if outside or color differs return set new color dfs four neighbors As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(R*C)
Space
O(R*C)
Pseudocode
dfs(r, c)
if outside or color differs return
set new color
dfs four neighbors 1.0x