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
|
Owner
|
@Lakshya182005 Star the repo as well...⭐ |
Author
|
thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: