Expand the pond

here is a link to my code: https://ide.codingblocks.com/s/195730
I’m getting correct submission only for half test cases. Please help!
how to write a recursive solution for the same.

@SWIFTY
hello mayur,
ur approach complexity is high roughly O(n^4) .
once go through this link -> https://csacademy.com/contest/archive/task/black-shapes

check its solution ,then try to optimise ur code ,if u still stuck then feel free to ask

Is it similar to boundary fill algorithm?

here is the link to my code : https://ide.codingblocks.com/s/196283

but its not giving any output i don’t know why

flood fill + grouping(union find)

it is running in infinite loop . make an extra array to track vistited state .

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.

im getting tle,what is possible optimization?code:https://ide.codingblocks.com/s/199348