N Queens Problem
Given an integer N
, find all possible placements of N
queens on an N x N
chessboard such that no two queens threaten each other.
Explanation:
A queen can attack another queen if they are in the same row, column, or diagonal. You need to find and print all valid configurations where queens do not attack each other.
Input:
Single integer 'N' representing the size of the chessboard and the number of queens.
Output:
Each line represents one valid chessboard configuration with 'N' queens. Each line contains 'N * N' elements (0 and 1) printed in a single row and separated by spaces. '1' indicates a queen's position, whereas '0' indicates an empty space.
Example:
Input:
4
Output:
0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0
0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0
Constraints:
1 <= N <= 10
- Time Limit: 1 sec
Note:
You do not need to print anything, as it is already handled. Just implement the function as specified.

AnswerBot
4mo
The N Queens Problem involves finding all possible placements of N queens on an N x N chessboard without threatening each other.
Use backtracking algorithm to explore all possible configurations.
Keep t...read more
Help your peers!
Add answer anonymously...
MAQ Software Software Developer interview questions & answers
A Software Developer was asked 6mo agoQ. Given a rotated sorted array, find the index of the first occurrence of a target...read more
A Software Developer was asked Q. Given an array, find the occurrence of each element in the array.
A Software Developer was asked Q. Given an array containing only 0s, 1s, and 2s, sort the array in-place.
Popular interview questions of Software Developer
A Software Developer was asked Q1. Given an array, find the occurrence of each element in the array.
A Software Developer was asked Q2. Given an array containing only 0s, 1s, and 2s, sort the array in-place.
A Software Developer was asked Q3. How do you sort a vector based on the order of another vector?
>
MAQ Software Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

