Implement N Queens Solution Dart#538
Merged
GouravRusiya30 merged 2 commits intoJun 6, 2026
Merged
Conversation
Member
|
Thanks for the contribution! The solution looks correct and the README entry has been added. One minor suggestion: the backtrack() method includes a col parameter that is never used. Inside the function, a local loop variable named col shadows it: void backtrack( Since the parameter is unused, it can be removed to simplify the method signature and improve readability. Also, consider adding a trailing newline at the end of the file to match common repository conventions. I verified that the README has been updated with an entry for the N-Queens Dart solution, so that requirement is satisfied. Overall, the backtracking implementation looks correct. Nice work! |
GouravRusiya30
approved these changes
Jun 6, 2026
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.

Pull Request Template
Description
This PR adds a solution for 51. N-Queens
Problem Description:
The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respectively.
Approach
Given its a N x N board we cant bruteforce all possible solutions since that may give us TLE. Instead what we can do is backtrack. We place a queen on each row and if it is safe, we continue otherwise we remove and move onto the next possible correct configuration
Dependencies:
Dart
Complexity
Time Complexity:
O(N!)Space Complexity:
O(N)Difficulty: Hard
Tags: Backtracking, Array
Put check marks:
Have you made changes in README file ?
How Has This Been Tested?
This solution has been tested by using the following scenarios:
n = 4
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
n = 1
Output: [["Q"]]
Make sure all below guidelines are followed else PR will get Reject: