Challenge - 5 Problems
Sudoku Solver Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Sudoku Board After One Backtracking Step
Given the initial Sudoku board and one step of backtracking filling the first empty cell, what is the printed board state?
DSA Python
board = [ [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] ] # After one backtracking step, the first empty cell (row 0, col 2) is filled with 4 board[0][2] = 4 for row in board: print(' -> '.join(str(num) for num in row) + ' -> null')
Attempts:
2 left
💡 Hint
Look at the first empty cell in the top-left row and what number backtracking tries first.
✗ Incorrect
Backtracking fills the first empty cell (row 0, col 2) with the smallest valid number, which is 4 here. Other options show wrong numbers or unchanged board.
🧠 Conceptual
intermediateUnderstanding Backtracking in Sudoku Solver
Which of the following best describes the role of backtracking in solving Sudoku puzzles?
Attempts:
2 left
💡 Hint
Think about how backtracking tries and undoes choices.
✗ Incorrect
Backtracking is a trial and error method that tries numbers in empty cells and backtracks if a number leads to no solution.
🔧 Debug
advancedIdentify the Error in Sudoku Validity Check
What error will this code raise when checking if a number can be placed in a Sudoku cell?
DSA Python
def is_valid(board, row, col, num): for i in range(9): if board[row][i] == num: return False for j in range(9): if board[j][col] == num: return False start_row = row // 3 * 3 start_col = col // 3 * 3 for i in range(start_row, start_row + 3): for j in range(start_col, start_col + 3): if board[i][j] == num: return False return True board = [[0]*9 for _ in range(9)] print(is_valid(board, 0, 0, 5))
Attempts:
2 left
💡 Hint
Check the loops and variable usage carefully.
✗ Incorrect
The code correctly checks row, column, and 3x3 box for the number. The board is initialized as a 9x9 grid of zeros, so no error occurs and True is returned.
❓ Predict Output
advancedFinal Sudoku Board After Complete Backtracking Solve
What is the final printed Sudoku board after the solver completes on this puzzle?
DSA Python
board = [ [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] ] # Assume solver fills all empty cells correctly solved_board = [ [5,3,4,6,7,8,9,1,2], [6,7,2,1,9,5,3,4,8], [1,9,8,3,4,2,5,6,7], [8,5,9,7,6,1,4,2,3], [4,2,6,8,5,3,7,9,1], [7,1,3,9,2,4,8,5,6], [9,6,1,5,3,7,2,8,4], [2,8,7,4,1,9,6,3,5], [3,4,5,2,8,6,1,7,9] ] for row in solved_board: print(' -> '.join(str(num) for num in row) + ' -> null')
Attempts:
2 left
💡 Hint
Check carefully for any zeros left in the final board.
✗ Incorrect
Option A shows the fully solved Sudoku board with no zeros. Other options have zeros indicating incomplete or incorrect solutions.
🚀 Application
expertMinimum Number of Backtracking Calls for a Sudoku Puzzle
If a Sudoku solver uses backtracking and the puzzle has 40 empty cells, what is the minimum number of recursive calls the solver must make to guarantee a solution?
Attempts:
2 left
💡 Hint
Consider how backtracking explores multiple possibilities per cell.
✗ Incorrect
Backtracking tries numbers and may retry multiple times per cell, so the number of calls is at least the number of empty cells but often much higher.
