We have already learnt how to generate combinations of identical items in a 1d array by taking levels as items (in increasing order only) and choices as selecting an empty box.
In this problem, we are given the queens as identical items, and there is a slight variation that instead of 1d array of boxes, we are given a 2d array/grid of the chessboard.
So, we will take the queens (in increasing order only) as the levels in the recursion tree, and the choice/edge will be selecting an empty cell after the last queen's cell.
Isn't it simple? Just replace the traversal over 1d array for selecting an empty box to traversal over 2d array for selecting an empty cell. But, please be careful that we need to traverse through the cells only after the last queen's cell (to avoid permutations).
Hence, we will skip all the rows less than the last queen's row, and also skip all the cells in the left of the last queen's row.
Thus, we will traverse through the cells in the ith row to the right of last queen's cell and all the cells in the bottom rows.
Please note what should be the base case of this problem?
Base case can be considered when we have made a decision for all of the queens, i.e. the queens placed so far (qpsf) is equal to the total number of queens available (n or tq). When we hit the base case, we will print the grid, by writing the 'q' for filled cells, else print '-' followed by tab space for the empty cell.