Imagine you're an aerial photographer capturing images of a tropical archipelago! You have a binary matrix representing a satellite view where 1 represents land and 0 represents water.
Your mission: find the largest island in this beautiful archipelago. An island is a group of connected land cells (1's) that touch each other horizontally or vertically - diagonal connections don't count!
Goal: Return the area (number of cells) of the largest island. If there are no islands, return 0.
Example: In a grid like [[1,1,0],[0,1,0],[0,0,1]], we have two islands - one with area 3 (the connected group) and one with area 1, so we return 3.
Input & Output
Visualization
Time & Space Complexity
Each cell is visited exactly once during the grid traversal and DFS exploration
Recursion stack can go as deep as m*n in worst case (entire grid is one island)
Constraints
- m == grid.length
- n == grid[i].length
- 1 β€ m, n β€ 50
- grid[i][j] is either 0 or 1