Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
For each land cell, DFS returns the area of its full island by summing all reachable land neighbors. Keep global max across all starts.
Every cell is visited at most once and contributes to exactly one component count. Returning 1 + recursive contributions gives the component area.
Updated Feb 2026