0
Leetcode Problem 695. Max Area of Island
695. Max Area of Island
AI Mock Interview
Leetcode Solutions
Depth-First Search (Recursive)
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize a variable
max_area
to keep track of the maximum island area found.
Iterate over each cell in the grid.
If the cell is land (value of 1) and has not been visited, perform a DFS from that cell.
During the DFS, mark the cell as visited and increment the current island's area count.
For each land cell, explore all 4-directionally connected land cells (up, down, left, right) that have not been visited.
After the DFS completes for an island, update
max_area
if the current island's area is larger.
Continue the process until all cells in the grid have been checked.
Return
max_area
as the result.
Depth-First Search (Iterative)
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...