Count nqueens problem

Please tell in which two ways (calls)does the count variable gets executed here

@malhotranaman83,

In this question we use backtracking to solve the problem hence if IsItsafe gives true value then we put a queen at a particular i,j as board[i][j]=true … Then for that case either of the possible outcomes take place

  1. The arrangement has a further arrangement where all N queens can be placed comfortably… In this case when we hit base case and then roll back to consider the second case we have to remove the placed queens on the board and have to start from place one …Hence in such case board[i][j]=false will be triggered.
  2. The arrangement has a further arrangement where queens clash and we cannot place all the queen in the arrangement. In such case we have to rollback and have to remove all the place queens and hence board[i][j]=false will remove the queen from i,j … In our case we have i=row and j=col …
1 Like