Max Area of Island, solved three ways

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Recursion tree

not called yet running now paused, waiting on a child call land call, finished: "= k" is what it returned ✕ returned 0 at once (out / water / sunk)

Call stack

Grid

Rows on the left, columns on top; the outer ring is off the grid

island areas
1land 0water 0sunk (colour = island) current dfs call outoutside the grid

Keyboard: ← → step, Space play or pause. Grids up to 8×13; paste LeetCode style [[0,1],[1,1]] or rows like 01, 11. Switching solution keeps the grid. All three are O(m·n) time. DFS returns each island's area up the call stack, BFS counts pops, and DSU keeps a running size per set.