Max Area of Island
You are given an m x n binary matrix grid. An island is a group of 1‘s (representing land) connected 4-directionally (horizontally or vertically). You may assume all four edges of the grid are surrounded by water.
The area of an island is the number of cells with a value 1 in the island.
Return all the pairs of row and col indexes which belong to maximum area of an island in grid.
Input:
grid = [["1","1","1","1","0"],
["1","1","0","1","0"],
["1","1","0","0","1"],
["0","0","1","1","0"]
]
Output:
[[0,0],
[1,0],
[2,0],
[2,1],
[1,1],
[0,1],
[0,2],
[0,3],
[1,3]
]
This problem is a grid traversal task. Treat each cell with value 1 as land and use DFS or BFS to explore 4-directionally connected cells, forming one island at a time. For every island, collect all its coordinates and measure its area by counting the cells in the connected component. Since the goal is to return the coordinates of the island with maximum area, keep track of the largest component seen so far and replace the answer whenever a larger one is found. A visited set or in-place marking prevents revisiting cells. The overall complexity is O(mn).