please check:
TLE on submission :(
There are some mistakes in your code:-
- As your board[][] contains βXβ or βOβ, which tells us about whether the next cell can be visited or not, you should be very careful while changing its element values, as during the recursive cases you have changed the value of board[i][j] = β1β if it can be visited but there will be case when you have taken this path but later on that path is blocked and you have to backtrack.
So, you should take care of its value like save it in a temp variable before recursion and after the recursive call is returned but not true then again assign that temp variable at that index. - inside the canplace() function you should compare board[i][j] with βOβ, bcoz this index maynot be βXβ but can be β1β which means it has been already visited and canβt visit again.
- One thing also, if path is not found then donβt print -1, print what is said in the question.
I Hope you are now able to solve this.
If doubt still exists then feel free to ask.
1 Like
Heyy, yes it worked after changing that condition in can plae function. Thanks a lot