N-Queens

Advanced Backtracking DSA practice problem on Onlearn.

Difficulty: hard.

Topics: N-Queens Problem: Finding All Distinct Solutions for n-Queens Placement, Backtracking, Recursion, Arrays, Time Complexity, Space Complexity, Optimization, Matrices, Hashing, constraints, backtracking, hashing, recursion, time complexity analysis, Backtracking Constraints.

The n queens puzzle is the problem of placing n queens on an n × n chessboard such that no two queens can attack each other. Given an integer n, return all distinct solutions to the n queens puzzle. Each solution contains a distinct board configuration of the queen's placement, where ‘Q’ and ‘.’ indicate a queen and an empty space respectively. Example: Input: n = 4 Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]] Explanation: There exist two distinct solutions to the 4 queens puzzle as shown below. Constraints: n is a positive integer.