bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 695. Max Area of Island

695. Max Area of Island

Leetcode Solutions

Depth-First Search (Recursive)

  1. Initialize a variable max_area to keep track of the maximum island area found.
  2. Iterate over each cell in the grid.
  3. If the cell is land (value of 1) and has not been visited, perform a DFS from that cell.
  4. During the DFS, mark the cell as visited and increment the current island's area count.
  5. For each land cell, explore all 4-directionally connected land cells (up, down, left, right) that have not been visited.
  6. After the DFS completes for an island, update max_area if the current island's area is larger.
  7. Continue the process until all cells in the grid have been checked.
  8. Return max_area as the result.
UML Thumbnail

Depth-First Search (Iterative)

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...