I am not able to understand how to approach this question
Please give the code for this question?
@namangarg31
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.
editorial code(https://ide.codingblocks.com/s/266259)
dont forget to hit like and mark resolved if cleared 
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.