← Questions

Number of islands as land is added

0
GoogleUberCodingLast asked Oct 2026

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.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding