Problem 200 counts components; this one measures them. The scan, the
four neighbours and the sink-before-you-recurse rule are unchanged — the single
edit is the return type. void becomes int,
and every call owes its caller 1 + down + up + right + left. The sum is
assembled on the way down and collapses on the way back up; watch the returns land.
1 + ∑(neighbour returns). Sinking in-place guarantees each cell contributes to exactly one island.
"Unlike LC 200's void sink, area(r, c) returns an int representing the total area of the island component rooted at (r, c)."
"The sum collapses in post-order: 1 (self) + down + up + right + left. Child branches evaluate first; when they return, the parent adds their results."
"While area(r, c) waits on Down, it sits suspended on the call stack holding 1. When Down returns 2, the parent records it and moves to Up."
"Off-grid and water return 0 immediately without allocating new frames. Worst-case space is O(m · n) call stack depth for a continuous spiral island."
1 + sum(children). Sinking is what guarantees each cell is counted once and only once.