Pond Size

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:
  1. Iterate all cells of matrix one by one
    1. If its not visited and cell has water call DFS to count connected ponds

Latest Source Code:
Github: PondSize.java


Output:

 
Author: Hrishikesh Mishra