Count the islands after each cell of a water grid becomes land.
Unlock detailed company stats for this questionUpgrade
You are given an initially all-water grid. At every iteration one cell becomes land. After each update, return the number of islands.
Solved with DSU: treat each cell as a node; when land appears, increase the island count, union with land neighbours, and decrement when two islands merge.
Community answers
No answers contributed by the community yet.
Related questions
Count the number of islands in a grid.Count the number of distinct islands in a grid.Implement countLakes to count the lakes within a given island of a grid.Related courses

Course

Course
Course
