I got the concept of N queen problem… but i am not able to write the code
how should i approach… how should i think?
N queen coding sol
@chaman9 hey use this algo to write your code:
- Start in the leftmost column
- If all queens are placed
return true - Try all rows in the current column.
Do following for every tried row.
a) If the queen can be placed safely in this row
then mark this [row, column] as part of the
solution and recursively check if placing
queen here leads to a solution.
b) If placing the queen in [row, column] leads to
a solution then return true.
c) If placing queen doesn’t lead to a solution then
unmark this [row, column] (Backtrack) and go to
step (a) to try other rows. - If all rows have been tried and nothing worked,
return false to trigger backtracking.
okay thanks… i will try out
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.