DFS Island Counter - Advanced Visualizer
5x5 grid with real-time code execution tracking
Step: 0 / 0
Click "Next" or "Play" to start the step-by-step execution.
Code Execution
def numIslands(grid):
count = 0
rows = len(grid)
cols = len(grid[0])
for i in range(rows):
for j in range(cols):
if grid[i][j] == '1':
count += 1
dfs(i, j)
return count
def dfs(row, col):
if row < 0 or row >= rows or col < 0 or col >= cols or grid[row][col] == '0':
return
grid[row][col] = '0'
dfs(row + 1, col)
dfs(row - 1, col)
dfs(row, col + 1)
dfs(row, col - 1)