N Queen Problem

Description :-

N Queen is a problem in which we placing N chess Queens on a  N x N chessboard in such a way that no two queens attack each other diagonally, horizontally and vertically.

 

Input :-

The first line contains a single integer N – the number of Queens and the size of the chessboard.

 

Output :-

A binary matrix which has “Q” for the blocks where queens are placed and  “_”  on other remaining places of chessboard.

 

Sample Input  :-

4

 

Sample Output  :-

 _  Q  _  _ 
 _  _  _  Q 
 Q  _  _  _ 
 _  _  Q  _

 

solution button

Comments

No comment yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact us





Scroll Up