Wrong answer in N-Queen Problem

Can someone pls tell me what is the mistake in my solution ?
The problem is just to solve N-Queens problem for 1<=n<=8;

Question link : https://www.codechef.com/problems/TIC04

Solution link : https://www.codechef.com/viewsolution/36882787

@priyanshi_garg
In function PlacenQUEEN
you need to first check for every place a queen can be placed or not
insted of Placenqueen
use:_
bool solvequeen(int board[d][d],int col)
{
int n=4;
if(col>=n)
return true;
for(int i=0;i<n;i++)
{

     if(issafe(board,i,col))
{
    board[i][col]=1;
    if(solvequeen(board,col+1))
        return true;
    board[i][col]=0;
}

}
return false;
}

1 Like

Thanks @amitkumar_fc

there is a little bug in ur code i solved it
you can see here https://pastebin.com/ZA9zfacn

1 Like

Thanks @sjsahil0844. I am really looking for the mistake in my code.

Can you pls explain that condition where you are checking whether the matrix cell contains queen or not. I think that as we are filling matrix row by row so there was no need to check for it. Am I right ??

1 Like

yaa

okk