Statements
You are given a
You can perform an add land operation that changes a water cell into land. An array positions
is provided, where each element positions[i] = [r
i
, c
i
]
indicates the cell (r
i
, c
i
)
, where the i
th
operation is applied.
Your task is to return an array of integers answer
, where answer[i]
gives the number of islands present in the grid after executing the i
th
operation.
An island is defined as a cluster of land cells connected horizontally or vertically (diagonal connections are not considered). The grid is assumed to be completely enclosed by water along its four boundaries.
Constraints:
1<= m
,n
,positions.length
<=104 1<= m * n
<=104 positions[i].length
==2 0<= r
i
< m
0<= c
i
< n