Challenge - 5 Problems
Sudoku Solver Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Partial Sudoku Board After One Backtracking Step
Given the partial Sudoku board and the backtracking step shown, what is the state of the board after placing the first valid number in the empty cell at row 0, column 2?
DSA C++
int board[9][9] = { {5,3,0,0,7,0,0,0,0}, {6,0,0,1,9,5,0,0,0}, {0,9,8,0,0,0,0,6,0}, {8,0,0,0,6,0,0,0,3}, {4,0,0,8,0,3,0,0,1}, {7,0,0,0,2,0,0,0,6}, {0,6,0,0,0,0,2,8,0}, {0,0,0,4,1,9,0,0,5}, {0,0,0,0,8,0,0,7,9} }; // First empty cell at (0,2) tries numbers 1 to 9 // Number 1 is valid and placed board[0][2] = 1;
Attempts:
2 left
💡 Hint
Check which numbers can be placed in the empty cell without breaking Sudoku rules.
✗ Incorrect
The first empty cell at (0,2) can accept number 1 without conflicts in row, column, or 3x3 box. So the board updates with 1 at that position.
🧠 Conceptual
intermediateWhy Backtracking Works for Sudoku Solving
Why is backtracking a suitable method to solve Sudoku puzzles?
Attempts:
2 left
💡 Hint
Think about how the algorithm handles wrong choices.
✗ Incorrect
Backtracking tries numbers one by one in empty cells. If a number causes a conflict later, it goes back and tries another number. This systematic trial and error ensures the puzzle is solved correctly.
🔧 Debug
advancedIdentify the Bug in Sudoku Validity Check Function
What is the bug in this validity check function for Sudoku, and what error will it cause?
bool isValid(int board[9][9], int row, int col, int num) {
for (int x = 0; x < 9; x++) {
if (board[row][x] == num) return false;
if (board[x][col] == num) return false;
}
int startRow = row - row % 3;
int startCol = col - col % 3;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (board[startRow + i][startCol + j] = num) return false;
}
}
return true;
}
Attempts:
2 left
💡 Hint
Look carefully at the condition inside the nested loops for the 3x3 box.
✗ Incorrect
Using '=' instead of '==' assigns num to the cell, corrupting the board and causing the function to return false incorrectly.
📝 Syntax
advancedCorrect Syntax for Recursive Sudoku Solver Function
Which option shows the correct syntax for the recursive call in a Sudoku solver function that tries to fill the board?
DSA C++
bool solveSudoku(int board[9][9]) { int row, col; if (!findEmptyCell(board, row, col)) return true; for (int num = 1; num <= 9; num++) { if (isValid(board, row, col, num)) { board[row][col] = num; // recursive call here ... board[row][col] = 0; } } return false; }
Attempts:
2 left
💡 Hint
Remember the syntax for if statements in C++.
✗ Incorrect
Option A uses correct syntax with parentheses and no extra semicolon after the if condition.
🚀 Application
expertNumber of Recursive Calls in Worst Case for Empty Sudoku Board
If the Sudoku solver uses backtracking on an empty 9x9 board (all cells empty), approximately how many recursive calls will it make in the worst case before finding a solution or concluding none exists?
Attempts:
2 left
💡 Hint
Consider the branching factor and depth of recursion in backtracking.
✗ Incorrect
Backtracking tries many possibilities for each empty cell. With 81 empty cells and up to 9 choices each, the worst case is exponential, leading to over a million calls.
