JavaScript clear solution beats 100% easy to understand
\nvar largestIsland = function(grid) {\n    return searchLargest(paintIsland(grid));\n};\nconst dir = [[1, 0], [-1, 0], [0, 1], [0, -1]];\n\nconst validate = (r
```\nvar largestIsland = function(grid) {\n    return searchLargest(paintIsland(grid));\n};\nconst dir = [[1, 0], [-1, 0], [0, 1], [0, -1]];\n\nconst validate = (row, col, grid) => row >= 0 && col >= 0 && row < grid.length && col < grid[0].length;\n\nconst paintIsland = grid => {\n    const islandMap = new Map();\n    let label = 2, area = 0;\n    const dfs = (x, y) => {\n        area++;\n        grid[x][y] = label; // paint the island to a new number\n        for(const [dx, dy] of dir) {\n            const row = x + dx;\n            const col = y + dy;\n            if(validate(row, col, grid) && grid[row][col] === 1) {\n                dfs(row, col);\n            }\n        }\n    }\n    for(let i = 0; i < grid.length; i++) {\n        for(let j = 0; j < grid[0].length; j++) {\n            if(grid[i][j] === 1) { \n                dfs(i, j);\n                islandMap.set(label, area);\n                area = 0;\n                label++;\n            }\n        }\n    }\n    return [grid, islandMap];\n}\n\nconst searchLargest = ([grid, map]) => {\n    let res = 0;\n    for(let i = 0; i < grid.length; i++) {\n        for(let j = 0; j < grid[0].length; j++) {\n            if(grid[i][j] === 0) {\n                let area = 1;\n                const seen = new Set();\n                for(const [di, dj] of dir) {\n                    if(!validate(i + di, j + dj, grid)) continue;\n                    const curr = grid[i + di][j + dj];\n                    if(map.has(curr) && !seen.has(curr)) {\n                        area += map.get(curr);\n                        seen.add(curr);\n                    }\n                }\n                res = Math.max(area, res);\n            }\n        }\n    }\n    return res ? res : grid.length * grid[0].length;\n}\n```
['Depth-First Search', 'JavaScript']