Pond Size
You have an integer matrix representing a plot of land, where the value at the location represents the height above sea level. A value of zero indicates water. A pond is a region of water connected vertically, horizontally or diagonally. The size of pond is the total number of connected water cells. Implement a method to return sizes of all ponds in the matrix.
Solution:
* – Traverse DFS over area
Algorithm:
- Iterate all cells of matrix one by one
- If its not visited and cell has water call DFS to count connected ponds
Latest Source Code:
Github: PondSize.java
Output: