Getting WA but works fine for all inputs locally.
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define test() int t; cin >> t; while( t-- )
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef vector < int > vi;
typedef pair < int , int > pi;
typedef vector < pair < int , int > > vpi;
typedef set < int > si;
vi adj[100001];
int vis[100001];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
bool board[8][8];
int qcount;
void displayBoard(int n){
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cout << (board[i][j]?"Q\t":"-\t");
}
cout << '\n';
}
}
bool isValid(int row, int col,int n){
for(int i=row-1; i>=0; i--){
if(board[i][col]) return false;
}
for(int i=row-1,j=col-1; i>=0,j>=0; i--,j--){
if(board[i][j]) return false;
}
for(int i=row-1,j=col+1; i>=0,j<n; i--,j++){
if(board[i][j]) return false;
}
return true;
}
void nQueen(int n,int i){
//base
if(i == n){
displayBoard(n);
cout << '\n';
qcount++;
return;
}
//
for(int j=0; j<n; j++){
if(isValid(i,j,n)){
board[i][j] = true;
nQueen(n,i+1);
board[i][j] = false;
}
}
}
void solve(){
int n;cin >> n;
nQueen(n,0);
if(qcount == 0)
cout << "Not Possible\n";
}
int main(){
crap;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// test(){
solve();
// }
}
Thanks for the help.