{"id":"d322a97f-dbd6-49a8-af18-16962b09e8a3","name":"N Queens - Branch And Bound","description":"1. You are given a number n, the size of a chess board.\r\n2. You are required to place n number of queens in the n * n cells of board such that no queen can \r\n kill another.\r\nNote - Queens kill at distance in all 8 directions\r\n3. Complete the body of printNQueens function - without changing signature - to calculate and \r\n print all safe configurations of n-queens\r\n\r\nUse sample input and output to get more idea.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit \r\n of question is.\r\n\r\nWrite recursive and not iterative logic. The purpose of the question is to aid learning recursion, branch and bound technique and not test you.\r\n","inputFormat":"A number n","outputFormat":"Safe configurations of queens as suggested in sample output","constraints":"1 <= n <= 10","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n boolean[][] board = new boolean[n][n];\r\n //write your code here\r\n \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"4\r\n","sampleOutput":"0-1, 1-3, 2-0, 3-2, .\r\n0-2, 1-0, 2-3, 3-1, .\r\n","questionVideo":"https://www.youtube.com/embed/yvt0emtFiIE","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"390c25ee-0cb3-4340-9acc-7edc63bec0c2","name":"N Queens - Branch And Bound","slug":"n-queens-branch-and-bound","type":1}],"next":{"id":"1a943abe-d658-4054-80a4-6416dd592006","name":"N queens -Branch and bound MCQ","type":0,"slug":"n-queens-branch-and-bound-mcq"},"prev":{"id":"2fdd92dc-251a-420e-ab3b-09b644452ade","name":"Abbreviations using Backtracking","type":3,"slug":"abbreviations-using-backtracking"}}}

N Queens - Branch And Bound

1. You are given a number n, the size of a chess board. 2. You are required to place n number of queens in the n * n cells of board such that no queen can kill another. Note - Queens kill at distance in all 8 directions 3. Complete the body of printNQueens function - without changing signature - to calculate and print all safe configurations of n-queens Use sample input and output to get more idea. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion, branch and bound technique and not test you.

{"id":"d322a97f-dbd6-49a8-af18-16962b09e8a3","name":"N Queens - Branch And Bound","description":"1. You are given a number n, the size of a chess board.\r\n2. You are required to place n number of queens in the n * n cells of board such that no queen can \r\n kill another.\r\nNote - Queens kill at distance in all 8 directions\r\n3. Complete the body of printNQueens function - without changing signature - to calculate and \r\n print all safe configurations of n-queens\r\n\r\nUse sample input and output to get more idea.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit \r\n of question is.\r\n\r\nWrite recursive and not iterative logic. The purpose of the question is to aid learning recursion, branch and bound technique and not test you.\r\n","inputFormat":"A number n","outputFormat":"Safe configurations of queens as suggested in sample output","constraints":"1 <= n <= 10","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n boolean[][] board = new boolean[n][n];\r\n //write your code here\r\n \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"4\r\n","sampleOutput":"0-1, 1-3, 2-0, 3-2, .\r\n0-2, 1-0, 2-3, 3-1, .\r\n","questionVideo":"https://www.youtube.com/embed/yvt0emtFiIE","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"390c25ee-0cb3-4340-9acc-7edc63bec0c2","name":"N Queens - Branch And Bound","slug":"n-queens-branch-and-bound","type":1}],"next":{"id":"1a943abe-d658-4054-80a4-6416dd592006","name":"N queens -Branch and bound MCQ","type":0,"slug":"n-queens-branch-and-bound-mcq"},"prev":{"id":"2fdd92dc-251a-420e-ab3b-09b644452ade","name":"Abbreviations using Backtracking","type":3,"slug":"abbreviations-using-backtracking"}}}
plane

Editor


Loading...

N Queens - Branch And Bound

hard

1. You are given a number n, the size of a chess board. 2. You are required to place n number of queens in the n * n cells of board such that no queen can kill another. Note - Queens kill at distance in all 8 directions 3. Complete the body of printNQueens function - without changing signature - to calculate and print all safe configurations of n-queens Use sample input and output to get more idea. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion, branch and bound technique and not test you.

Constraints

1 <= n <= 10

Format

Input

A number n

Output

Safe configurations of queens as suggested in sample output

Example

Sample Input

4

Sample Output

0-1, 1-3, 2-0, 3-2, . 0-2, 1-0, 2-3, 3-1, .

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode