Problem statement

https://binarysearch.com/problems/Sudoku-Validator/

Solution

Variation of Leetcode 0036. Valid Sudoku.

Complexity

It is O(81) for time and space.

Code

class Solution:
    def solve(self, board):
        for row in chain(board, zip(*board)):
            if set(row) != set(range(1, 10)): return False
            
        for x, y in product([1,4,7],[1,4,7]):
            cand = [board[x+i][y+j] for i,j in product([-1,0,1],[-1,0,1])]
            if set(cand) != set(range(1, 10)): return False
        
        return True