From 22399def5e83ca7a9a128a1236d0b6c01f880b1d Mon Sep 17 00:00:00 2001 From: MayankSharma-2812 Date: Thu, 22 Jan 2026 11:55:40 +0530 Subject: [PATCH] Improve N-Queens input validation and solution counting clarity --- Backtracking/NQueens.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Backtracking/NQueens.js b/Backtracking/NQueens.js index 307c66dc04..18daad5611 100644 --- a/Backtracking/NQueens.js +++ b/Backtracking/NQueens.js @@ -1,8 +1,9 @@ class NQueens { constructor(size) { - if (size < 0) { - throw RangeError('Invalid board size') + if (size <= 0) { + throw RangeError('Board size must be a positive integer') } + this.board = new Array(size).fill('.').map(() => new Array(size).fill('.')) this.size = size this.solutionCount = 0 @@ -40,7 +41,7 @@ class NQueens { solve(col = 0) { if (col >= this.size) { this.solutionCount++ - return true + return } for (let i = 0; i < this.size; i++) { @@ -50,8 +51,6 @@ class NQueens { this.removeQueen(i, col) } } - - return false } printBoard(output = (value) => console.log(value)) {