...

/

N-Queens

N-Queens

Try to solve the N-Queens II problem.

Statement

Given an integer, n, representing the size of an n x n chessboard, return the number of distinct ways to place n queens so that no two queens attack each other. A queen can attack another queen if they are in the same row, column, or diagonal.

Constraints:

  • 11 \leq n 9\leq 9

Examples

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

N-Queens

1.

What is the correct solution to the 1-Queens problem?

A.

0

B.

1

C.

2

D.

4


1 / 5

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in Solution.java in the following coding playground.

Java
usercode > Solution.java
import java.util.*;
public class Solution {
public static int totalNQueens(int n) {
// Replace this placeholder return statement with your code
return -1;
}
}
N-Queens II

Access this course and 1200+ top-rated courses and projects.