Leetcode 51: N-Queens

The n-queens problem is about arranging n queens on an n x n chessboard such that no queen attacks another queen.

It turns out that this is quite a common example for using a backtracking algorithm. However my initial solution involved going through permutations of the column positions for each queen. Here are my whiteboard notes and source code for this solution and then my implementation of a more traditional backtracking solution further down:

And here is my explanation and implementation of backtracking solution (iterative):

This entry was posted in programming and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *