← 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 empty m x n grid initially filled with water. We may perform an addLand operation where positions[i] = [ri, ci] turns the cell (ri, ci) into land. Return an array answer where answer[i] is the number of islands after the ith operation. An island is a maximal group of horizontally or vertically adjacent land cells.
1 <= m, n <= 501 <= positions.length <= 50positions[i].length == 20 <= ri < m and 0 <= ci < nm = 3, n = 3 positions = [[1, 0], [0, 1], [2, 2], [3, 3]]
[1, 1, 2, 3]
(1, 0), there is 1 island.(0, 1), there is still 1 island (since it is connected to the first cell).(2, 2), there are 2 islands (since it is not connected to the first island).(3, 3), there are 3 islands.m = 5, n = 7 positions = [[0, 0], [0, 1], [1, 1], [1, 0], [2, 2], [3, 3], [3, 4]]
[1, 1, 1, 2, 2, 3, 3]