Expand the Pond

Hii , I’m getting run time error in this problem. I’m finding all the connected parts first and then by brute force i’m trying to connect every two pair . So my answer is max of these connected parts. 3 out of 6 test case are passing and rest of them getting runtime error. here is my solution

@knigh_t
can you please explain more about your solve() and tryIT() function.

One optimization in this question can be, assign some id to every connected component and store the size for it also, and then for every (i,j) cell having mat[i][j]==0, do sum of all unique connected components and add 1 to it for if we convert mat[i][j] 1. take max of all these. That will be your answer.

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.