Check Sudoku board configuration is valid or not(Using Bitmasking)
Using arrays in the prior method allowed us to monitor which numbers have emerged in every row, column, and sub-matrix. Now, by employing bit manipulation, we can make this more efficient; we represent the existence of numbers with bits in an integer, therefore lowering memory use and enhancing time complexity as well. Apart from verifying and marking visited values in row, column, and sub-matrix, the implementation processes remain the same as above technique. Methodical, step-by-step approach: C++ C Java Python C# Time complexity O(n^2), where n = Sudoku matrix size—that is, 9. This is so as we go across all n*n matrix cells iteratively.O(n) auxiliary space since we track the seen numbers for rows, columns, and sub-matrix using three arrays (rows, cols, subMat), each of size n. Bitwise operations use the integer each array element carries.
Check Sudoku board configuration is valid or not(Using Bitmasking) Read More »