The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.
Each solution contains a distinct board configuration of the n-queens' placement, and is represented as an array containing the column for each row of the matrix.
Example:
Input: n = 4 Output: [[1, 3, 0, 2], [2, 0, 3, 1]] Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above
Constraints:
1 <= n <= 9
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Free plan: 30 tutor messages. Premium is unlimited.