SOLVE

LATER

N-Queens

Problem

Editorial

Analytics

Given a chess board having $$N \times N$$ cells, you need to place $$N$$ queens on the board in such a way that no queen attacks any other queen.

**Input:**

The only line of input consists of a single integer denoting $$N$$.

**Output:**

If it is possible to place all the $$N$$ queens in such a way that no queen attacks another queen, then print $$N$$ lines having $$N$$ integers. The integer in $$i^{th}$$ line and $$j^{th}$$ column will denote the cell $$(i,j)$$ of the board and should be $$1$$ if a queen is placed at $$(i,j)$$ otherwise $$0$$. If there are more than way of placing queens print any of them. If it is not possible to place all $$N$$ queens in the desired way, then print "Not possible" (without quotes).

**Constraints:**

$$1 \le N \le 10$$.

Time Limit:
1.0 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
C,
C++,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala 2.11.8,
Swift,
Visual Basic

Initializing Code Editor...

{"8106ceb": "/pagelets/problems-hint/algorithm/n-queensrecursion-tutorial/", "8106cd4": "/pagelets/problem-author-tester/algorithm/n-queensrecursion-tutorial/", "8106d01": "/pagelets/recommended-problems/algorithm/n-queensrecursion-tutorial/", "8106c22": "/pagelets/show-submission/algorithm/n-queensrecursion-tutorial/", "8106cbb": "/pagelets/suggested-problems/algorithm/n-queensrecursion-tutorial/"}

{}

realtime.hackerearth.com

80

fb23a1775c0a2ed573fb28ceaf322cf553e69baa

58a29e5cae2309f04b28

/realtime/pusher/auth/