Max Area of Island
You are given an m x n grid of numbers, where 1 is land and 0 is water. An island is a group of 1s joined horizontally or vertically (not diagonally), and its area is the number of cells in it.
Return the area of the largest island in the grid, or 0 if the grid has no land.
Constraints
1 <= m, n <= 50grid[r][c]is0or1
Examples
Example 1
Input: grid = [[0,1,1,0,0,0],[0,1,0,0,1,1],[0,0,0,1,1,0],[1,0,0,0,1,0],[1,1,0,0,0,0]] Output: 5
There are three islands with areas 3 (top left), 5 (the right-hand group) and 3 (bottom left). The largest is 5.
Example 2
Input: grid = [[0,0,0],[0,0,0]] Output: 0
There is no land, so the answer is 0.
Example 3
Input: grid = [[1,0,1],[0,1,0],[1,0,1]] Output: 1
Five separate one-cell islands: corners don't connect. The largest has area 1.
JavaScript you'll use: Graphs and grids in JavaScript Recursion, the call stack and memoization
/**
* @param {number[][]} grid
* @return {number}
*/
function maxAreaOfIsland(grid) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.