I have doubt in base case. how will i identified that any element will be last or maximum elements have been visited

my code -> https://ide.codingblocks.com/s/460315

hello @chandreshmaurya

here for this problem ur return type should be int.

where ur function should return what is the maximum number of cells that can be visited from cell (i,j).

here at each step u have eight option but u can pick only one (the path that visit maximum numner of cells).

its like 1 + max( among 8 path, that visit highest no of cells)
check this->

solve(i,j) returns maximum cell u can visit from (i,j).

since we have 8 ways to proceed from (i,j) , we are trying all.
and picking one that visits maximum cells.

solve(i,j) = 1+ max( all eight ways)

sir, in line no. 8 , why are we checking for a[i][j] == 0 ?

…

ss
because in input format they have mentioned that cell which are marked 0 are not part of matrix.
so we are chekcing for the same, if it 0 , then simply we are returning 0 becuase it is not part of matrix

okay sir, it’s clear now. Thank you

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.