Challenge: Place N Queens on an NxN Chessboard
Explore how to place N queens on an NxN chessboard with no conflicts by using recursion. Understand how to check safe positions and apply backtracking techniques to systematically solve the challenge. This lesson strengthens your grasp of algorithmic problem solving and recursive design.
We'll cover the following...
Problem statement
You are given an NxN chessboard, and you are required to place N queens on this chessboard such that no queen is under threat from any other queen.
In chess a queen can move any number of steps horizontally, vertically, or diagonally.
This means that no queen should share a row, column, or diagonal with another queen.
Input
As input, your function will take a number n, which is the size of the board, and a 2-D list of strings as board, which is a grid where each row is a list of strings. Each string represents a cell on the board, initially set to ‘-’ to show that the cell is empty.
n = 4
board = [["-", ...