TLE on submission :(

please check:

There are some mistakes in your code:-

  1. 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.
  2. 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.
  3. 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