Problem
Ask
Submissions

Problem: N-Queens

Medium
30 min
Explore the N-Queens puzzle and learn how to use the backtracking algorithm to place n queens on an n×n chessboard so no two queens attack each other. Understand the problem constraints, implement solutions in a coding environment, and practice this classic coding interview challenge.

Statement

The N-Queens puzzle is a classic problem in which the goal is to place n queens on an n ×\times n chessboard so that no two queens can attack each other.

In chess, a queen can move any number of squares horizontally, vertically, or diagonally. Therefore, no two queens can be placed in the same row, column, or diagonal.

Given an integer n, return all distinct valid arrangements of n queens on the board. Each arrangement should be represented as a list of strings, where each string corresponds to a row of the board. Within each string, 'Q' denotes a queen and '.' denotes an empty square.

Note: You can return the solutions in any order.

Constraints:

  • 11 \leq n 9\leq 9

Problem
Ask
Submissions

Problem: N-Queens

Medium
30 min
Explore the N-Queens puzzle and learn how to use the backtracking algorithm to place n queens on an n×n chessboard so no two queens attack each other. Understand the problem constraints, implement solutions in a coding environment, and practice this classic coding interview challenge.

Statement

The N-Queens puzzle is a classic problem in which the goal is to place n queens on an n ×\times n chessboard so that no two queens can attack each other.

In chess, a queen can move any number of squares horizontally, vertically, or diagonally. Therefore, no two queens can be placed in the same row, column, or diagonal.

Given an integer n, return all distinct valid arrangements of n queens on the board. Each arrangement should be represented as a list of strings, where each string corresponds to a row of the board. Within each string, 'Q' denotes a queen and '.' denotes an empty square.

Note: You can return the solutions in any order.

Constraints:

  • 11 \leq n 9\leq 9