Implement countLakes to count the lakes within a given island of a grid.
Unlock detailed company stats for this questionUpgrade
Given a large M x N grid (1 = land, 0 = water/ocean) with multiple disconnected islands surrounded by ocean, and an API countLakes(island, coordinates) where coordinates is a point belonging to the given island, return the number of lakes within that particular island.
A lake is a water region completely enclosed by land. Water connected to the ocean is not counted. An island can have multiple lakes, and there is ocean outside the grid as well.
Example:
0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0
There are 2 disconnected islands. If coordinates belongs to the first island, countLakes returns 1, since it has one enclosed lake.
Community answers
No answers contributed by the community yet.


