Number of Islands II
Hard · Graphs · about 30 minutes
Asked at Uber, Google, Amazon, Meta.
An m × n grid starts as all water. positions[i] = [r, c] turns cell (r, c) into land (it may already be land). After each operation, return the number of islands (4-directionally connected land groups).