Right approach?


please check my code, if the approach is right, please tell the error in code
else what is the right approach?

hi @goyalvivek
This problem can be done using “recursion/dfs and similar” fashion. once you visit a cell, then visit all the cells that can be visited from this cell and also visit the cells that can be further visited from the next reachable cells.

refer this -->

is my approach correct?

if u see ur visit function, its doing nothing… also it tries to go out of bound (i<0 && j<0)… no where u are using the concept of backtracking…

please correct my code and add comments for understanding

go through the code i shared above…

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.