← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given an n x n binary matrix grid. You may change at most one 0 to 1. Return the size of the largest island after applying this operation. An island is a 4-directionally connected group of 1s.
Example 1:
Input: grid = [[1,0],[0,1]] Output: 3 Explanation: Change the first row, first column 0 to 1, then merge two 1s groups to form a 3-island.
Example 2:
Input: grid = [[1,1],[1,0]] Output: 4 Explanation: Change the second row, second column 0 to 1, then you get a 4-island.
Example 3:
Input: grid = [[1,1],[1,1]] Output: 4 Explanation: Can't change any 0 to 1, so the largest island remains 4.
n == grid.lengthn == grid[i].length1 <= n <= 500grid[i][j] is either 0 or 10 to 1.