N queen using recursion and backtracking

In test case 3 where input is 11 and output is supposed to be the count of possible configurations, it is showing time limit exceeded. The time that it shows is around 5.5 sec whereas on code blocks it is executing in 2 sec. What changes are required in the code?
#include
using namespace std;

bool isValid(int board[][15],int i, int j, int n){
///checking jth column
for(int row=0;row<i;row++){
if(board[row][j]==1) return false;
}
///checking left diagonal
int x=i;
int y=j;
while(x>=0 && y>=0){
if(board[x][y]==1) return false;
x–;
y–;
}
///checking right diagonal
x=i;
y=j;
while(x>=0 && y<n){
if(board[x][y]==1) return false;
x–;
y++;
}
return true;
}

void solns(int board[][15],int n, int &cnt, int i){
if(i==n){
cnt++;
return;
}

for(int j=0;j<n;j++){
    if(isValid(board,i,j,n)){
        board[i][j]=1;
        solns(board,n,cnt,i+1);
        board[i][j]=0;

    }
}

}

int main() {
int n; cin>>n;
int board[15][15]={0};
int cnt=0;
solns(board,n,cnt,0);
cout<<cnt;
return 0;
}

plz confirm what changes are required in the code

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.

What are the changes required in the code? Why is it failing in 1 test case?

it is tough to read a part of a code.
pleaase see this full code here-;

I’m not able to understand your code. This is my code:


Plz check and advise

actually when n is large then you will not be able to build the whole board as using recursion will result in an stackoverflow!!!

therefore you need to pre calculate the answers and print them finally

How do we pre calculate the answer?

its a series , use bitmasking to solve n queen problem , that is quite fast , or either print the series.

if you know that your code is correct and its only due to limitations of the compiler that you cant figure out the answer, then simply search the big answers on net and print them out.