36 Valid Sudoku

Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.

The Sudoku board could be partially filled, where empty cells are filled with the character'.'.

A partially filled sudoku which is valid.

Note: A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated. (A completely empty board is a valid square).

The Idea: A board is valid if all the rows, columns, and squares contain no duplicate integers.

Complexity: O(n^2) time and O(n) space with n is the len(sqrt(board))

Discussion

  • If the board is not necessarily 9x9, and if we wanted to generalize this algorithm. Here are some of the changes that need to be made.

    • The board must be a perfect square. e.g. 0^2, 1^1, 2^2 ... , n^n

    • squarevariable should then become math.sqrt(dim)

Last updated

Was this helpful?