-
-
Notifications
You must be signed in to change notification settings - Fork 100
52. N-Queens II #243
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
base: main
Are you sure you want to change the base?
52. N-Queens II #243
Conversation
Reviewer's GuideImplement N-Queens II solution using backtracking to explore row-by-row placements and track attacked columns and diagonals, supplemented with detailed approach and complexity comments. Class diagram for the Solution class in N-Queens IIclassDiagram
class Solution {
+int totalNQueens(int n)
}
Solution : -int count
Solution : -unordered_set<int> cols
Solution : -unordered_set<int> diag
Solution : -unordered_set<int> anti_diag
Solution : -void backtrack(int row)
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for raising the PR, the owner will be review it soon' keep patience, keep contributing>>>!!! make sure you have star ⭐ the repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@Lakshya182005 Star the repo as well...⭐ |
|
thank you! |
PR Title Format: 52. N-Queens II.cpp
Intuition
Row-by-Row Safe Placement
Approach
Backtracking with Row-by-Row Placement
Initialization
countto0to store the number of valid solutions.cols– columns where a queen is already placed.diag– main diagonals under attack (row + col).anti_diag– anti-diagonals under attack (row - col).Iteration (Row-by-Row Backtracking)
row = 0).cols,diag, oranti_diag).cols.row + coltodiag.row - coltoanti_diag.cols,diag, andanti_diag.row == n, all queens are placed safely. Incrementcount.Termination
Return the total count of valid N-Queens solutions.
Code Solution (C++)
Related Issues
Closes #242
By submitting this PR, I confirm that:
Summary by Sourcery
New Features: