Skip to content
Discussion options

You must be logged in to vote

We need to optimize the Sudoku solver by reducing the time complexity of validity checks. The previous approach checked each digit's validity by scanning the entire row, column, and 3x3 box, which is inefficient. Instead, we can use arrays to keep track of which digits are already present in each row, column, and box. This allows us to check the validity of a digit in constant time.

Approaches

  1. Initialization: Initialize three arrays ($rows, $cols, $boxes) to keep track of digits present in each row, column, and 3x3 box.
  2. Preprocessing: Populate these arrays based on the initial board configuration.
  3. Backtracking with Memoization: Use backtracking to try digits 1-9 for each empty cell, but …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Aug 31, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Aug 31, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants