N-Queens
Hard
Backtracking
Recursion
Place N queens on an NxN board so no two attack each other.
Input: N
Output: number of solutions
Constraints
See problem-specific constraints. Optimized solution required.
Examples
Example 1:
Input: 4
Output:
Example 2:
Input: 4
Output:
Hints
Consider a recursion approach.
Think about time complexity.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console