Number of islands as land is added

0
Remix

A grid starts as all water. Positions are turned into land one at a time; after each addition, return the current number of islands (land cells connected up, down, left or right). Use union-find so each addition is nearly constant time.

GoogleUberTechnical phone screenLast asked Oct 2026
No answer yet. Write the first one; the best answer gets endorsed.