Expand the pond

Can you please tell how should i start with this problem

Hello @singhsimran567 hey, use this approach, it is same as in the solution, group id is parent, black is 1, white is zero,
in first mark all the regions by their size
suppose
1 1 0
0 0 1
0 0 1
mark it as
2 2 0
0 0 2
0 0 2
these are the size of the ponds also mark them visited while iterating so u do not iterate over the same group again
and using DSU mark the parent of each cell
now iterate over the matrix again
only look for zeroes
once u find a zero
look for the elements adjacent to and pick the value of the elements that have diff parents add them and add 1 to it, to include this zero as well
this will solve your question
try to go this way:
if you still have any doubt you can ask here:
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.