This function solves the N Queen problem using Backtracking . It mainly uses solveNQUtil ( ) to solve the problem . It returns False if queens cannot be placed , otherwise , return True and prints placement of queens in the form of 1 s . Please note that there may be more than one solutions , this function prints one of the feasible solutions .
def solveNQ ( ) : NEW_LINE INDENT board = [ [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] ] NEW_LINE if ( solveNQUtil ( board , 0 ) == False ) : NEW_LINE INDENT printf ( " Solution ▁ does ▁ not ▁ exist " ) NEW_LINE return False NEW_LINE DEDENT printSolution ( board ) NEW_LINE return True NEW_LINE DEDENT