Need help in Expand the pond problem

URL: https://ide.codingblocks.com/s/108216

How to count the number of adjacent 1’s in the array? I have implemented the problem, but I cannot build a robust logic for calculating adjacent 1’s.

Thanks in Advance.

First we can use a flood fill algorithm to determine the black shapes and their sizes. Then we can take each white cell (there’s no point in changing the colour of a black cell) and see what happens if we choose it. We need to check its black neighbouring cells. We take the shapes of the black neighbours, being careful not to choose the same shape twice, and sum their sizes. The answer is the maximum of these sums plus 11 (for the white chosen cell)

for more details see the implementation…

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.