Given a grid of 1s (land) and 0s (water), return the area of the largest island, or 0 if there is no land.
Before you code
It is the island-counting scan with one change: the flood fill returns how many cells it marked.
Hints
area(r, c)returns 0 for water, out-of-range or visited cells.- Otherwise mark the cell and return
1 + areaof the four neighbors. - Keep the maximum over all starts.
Production & complexity notes
When solving Max area of island on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Depth-first search to reinforce the underlying pattern.
What it practices
DFS that returns a value, from Depth-first search.