Back to problems

Number of Islands II

Algorithm · Uber · Hard

You begin with an m x n matrix in which every cell is water. For each entry positions[i] = [ri, ci], apply an addLand operation that changes cell (ri, ci) to land. Produce an array answer such that answer[i] records the island count immediately after the ith operation. An island is a maximal set of land cells connected through horizontal or vertical adjacency. Examples Example 1: Input: m = 3, n = 3, positions = [[0,0],[0,1],[1,2],[2,1],[1,1]] Output: [1,1,2,3,1]…

Checking your access…