Complete the code to check if a number is already in the given row.
for (int col = 0; col < 9; col++) { if (board[row, col] == [1]) { return false; } }
The code checks if the number num is already present in the specified row. If yes, it returns false.
Complete the code to check if a number is already in the given column.
for (int row = 0; row < 9; row++) { if (board[row, col] == [1]) { return false; } }
The code checks if the number num is already present in the specified column. If yes, it returns false.
Fix the error in calculating the starting row of the 3x3 box.
int boxStartRow = row - (row [1] 3);
To find the starting row of the 3x3 box, we use the remainder operator % to find how far the current row is inside the box.
Fill both blanks to check if a number is already in the 3x3 box.
for (int r = boxStartRow; r < boxStartRow + 3; r++) { for (int c = boxStartCol; c < boxStartCol + 3; c++) { if (board[r, c] == [1]) { return false; } } }
The code checks if the number num is already present in the 3x3 box. If yes, it returns false.
Fill all three blanks to complete the recursive backtracking function call and board update.
if (SolveSudoku(board)) { return true; } else { board[[1], [2]] = [3]; }
If the recursive call fails, we reset the cell at row, col back to 0 to backtrack and try other numbers.
