DSA-Bootcamp-Java icon indicating copy to clipboard operation
DSA-Bootcamp-Java copied to clipboard

SudokuSolver is not checking isSafe for rows correctly.

Open Akhil-Selukar opened this issue 1 year ago • 1 comments

description : In isSafe method below loop is intended to check if the number we are trying to insert is already available in the row or not. But below loop is iterating over columns and not on rows so it is checking if the number already exists in column or not instead of row.

// check the row
for (int i = 0; i < board.length; i++) {
    // check if the number is in the row
    if (board[row][i] == num) {
        return false;
    }
}

Link for code snippet : https://github.com/kunal-kushwaha/DSA-Bootcamp-Java/blob/6bc4d8bf8ac5e434ac9083e1c01210e42f2a762c/lectures/14-recursion/code/src/com/kunal/backtracking/SudokuSolver.java#L81C9-L86C10

Akhil-Selukar avatar Oct 02 '24 18:10 Akhil-Selukar