I’m not able to come up with a logical way to solve this problem please help.
Need help with logic
Hey @amanb25
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
i tried but I’m not able to solve it, can you provide me with the code so i can follow through and understand
Hey check this :
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.