Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NQueens in Java #1531

Merged
merged 4 commits into from
Dec 27, 2020
Merged

Conversation

YASH01009
Copy link
Contributor

Have you read the Contributing Guidelines on Pull Requests?

(Yes)

Description

(NQueens added in Java)

Checklist

  • [Y] I've read the contribution guidelines.
  • [Y] I've checked the issue list before deciding what to submit.
  • [Y] I've edited the README.md and link to my code.

Related Issues or Pull Requests

(Issue #1524 is solved here)

Copy link
Owner

@HarshCasper HarshCasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest Code looks good to me!

Please make these changes, and it will be good to merge 👍

Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
boolean[][] board = new boolean[n][n];
//write your code here
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Comment is redundant. If you are solving a CP Problem from an Online Portal, prefer to add the link as well.

return;
}

for(int col=0; col<board.length; col++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put apt comments on your Code for better explainability?

@@ -0,0 +1,61 @@
/**
N-Queens problem is a famous problem
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, please add further information about the Algorithm

@YASH01009
Copy link
Contributor Author

@HarshCasper changes done !!

Space Complexity : O(n^2)
Time Complexity : upperbounded by O(n^n)

**/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line at the EOF

rdiag[row-col+board.length-1] = true;
board[row][col] = true;
solve(board, cols, ndiag, rdiag, row+1, asf+row+'-'+col+", ");
// backtrack
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the comments more understandable?

for(int col=0; col<board.length; col++) {
if(cols[col] == false && ndiag[row+col] == false &&
rdiag[row-col+board.length-1] == false) {
// place the queen
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the comments more understandable?

@YASH01009
Copy link
Contributor Author

@HarshCasper changes done !!

@HarshCasper HarshCasper merged commit 161cc9c into HarshCasper:master Dec 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants