You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical). 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 the maximum area of an island in grid. If there is no island, return 0.
Example 1
Input: grid = [[1,1,0,0],[1,0,0,1],[0,0,1,1]]
Output: 3
Explanation: The top-left island is (0,0), (0,1), (1,0), with area 3. The bottom-right island is (1,3), (2,2), (2,3), also area 3. The largest area is 3.
Example 2
Input: grid = [[0,0,0,0,0,0,0,0]]
Output: 0
Explanation: The grid has no land, so the answer is 0.
Example 3
Input: grid = [[1]]
Output: 1
Explanation: The single land cell forms an island of area 1.
Scan for land cells; from each unvisited one, flood-fill its whole island counting cells, sinking each cell as you visit it so it isn't counted twice.
Run checks all cases above. Submit evaluates all test cases.