rows rows and cols columns, all water at first. Builders fill cells one by one: fills[t] = [r, c] means that at step t the cell in row r, column c becomes land. The same cell may appear in fills more than once; filling it again changes nothing.
An **island** is a group of land cells connected through their sides (horizontally or vertically, not diagonally). Everything beyond the grid edges is water.
Return an array whose t-th element is the number of islands right after step t.
Recounting the whole map after every step is too slow; try to update the answer faster.rows=2, cols=3, fills=[[0, 0], [1, 2], [0, 1], [0, 2]] → [1, 2, 2, 1]
After the first fill there is one island, after the second there are two. Cell (0, 1) touches (0, 0), so there are still two. Cell (0, 2) touches both (0, 1) and (1, 2), merging everything into one island.
rows=1, cols=1, fills=[[0, 0], [0, 0]] → [1, 1]
Filling a cell that is already land changes nothing.
rows=2, cols=3, fills=[[0, 0], [1, 2], [0, 1], [0, 2]]
[1, 2, 2, 1]
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.