The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Return all distinct solutions to the n-queens puzzle.
Input: n = 4
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Topics: backtracking
Asked by: Amazon, Google, Meta, Microsoft, Apple
Time complexity: O(n!). Space complexity: O(n²).