Where am I doing wrong?
Expand the pond
All you have to do is first find the connected areas and store their areas in a map. Then for every dry cell check its all four neighbors and put those in the set to avoid redundant neighbour. Then check one by what will the increase in the area if that neighbor is set to 1 and maximize your answer accordingly.
I did not get it.Can you please explain this.
Can you please clear my doubt.
Just do Floodfill and mark the connected area with unique numbers.
For ex -:
1 0 0 0 1
1 0 1 1 1
0 1 0 0 0
Then after flood fill it will look like this -:
2 0 0 0 3
2 0 3 3 3
0 4 0 0 0
So now all you have to do is to check for every zero to extend your area.
Check in all four direction ( L R U D ) , and add that to set to avoid duplicates.
Then traverse the set and check which one makes the biggest area expansion.
You can refer this code for better understanding -:
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.