May 7, 2024, 4:52 p.m. | FatimaAlam1234

DEV Community dev.to


class Solution {
public:
void solve(int i,int& n,vector<string> &tmp, vector<vector<string>> &ans,vector<bool> &c,vector<bool> &md,vector<bool> &td){
if(i==n){
ans.push_back(tmp);
return;
}
string str(n,'.');
for(int j = 0; j < n; j++){
if((c[j]==false&&md[i-j+n]==false&&td[i+j]==false)){
str[j] = 'Q';
c[j] = true;md[i-j+n]=true;td[i+j] = true;
tmp.push_back(str);
solve(i+1,n,tmp,ans,c,md,td);
tmp.pop_back();
str[j] = '.';
c[j] = false;md[i-j+n]=false;td[i+j] = false;
}
}
}
vector<vector<string>> solveNQueens(int n) {
vector<vector<string>> ans;
vector<string> tmp;
vector<bool> c(n,false),md(2*n+3,false),td(2*n+3,false);
solve(0,n,tmp,ans,c,md,td);
return ans;
}
};

class false public solution solve string true vector

Software Engineer for AI Training Data (School Specific)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Python)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Tier 2)

@ G2i Inc | Remote

Data Engineer

@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania

Artificial Intelligence – Bioinformatic Expert

@ University of Texas Medical Branch | Galveston, TX

Lead Developer (AI)

@ Cere Network | San Francisco, US