write a function validsolutionvalidatesolutionvalidsolution that accepts a 2d array representing a sudoku board and returns true if it is a valid solution or false otherwise the cells of the sudoku board may also contain 0 s which will represent empty cells boards containing one or more zeroes are considered to be invalid solutions the board is always 9 cells by 9 cells and every cell only contains integers from 0 to 9 more info at http en wikipedia orgwikisudoku using dicthashtable without hashtabledict check rows check columns check regions if everything correct using set using dict hash table without hash table dict check rows check columns check regions if everything correct using set
from collections import defaultdict


def valid_solution_hashtable(board):
    for i in range(len(board)):
        dict_row = defaultdict(int)
        dict_col = defaultdict(int)
        for j in range(len(board[0])):
            value_row = board[i][j]
            value_col = board[j][i]
            if not value_row or value_col == 0:
                return False
            if value_row in dict_row:
                return False
            else:
                dict_row[value_row] += 1

            if value_col in dict_col:
                return False
            else:
                dict_col[value_col] += 1

    for i in range(3):
        for j in range(3):
            grid_add = 0
            for k in range(3):
                for l in range(3):
                    grid_add += board[i * 3 + k][j * 3 + l]
            if grid_add != 45:
                return False
    return True



def valid_solution(board):
    correct = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    
    for row in board:
        if sorted(row) != correct:
            return False

    
    for column in zip(*board):
        if sorted(column) != correct:
            return False

    
    for i in range(3):
        for j in range(3):
            region = []
            for line in board[i*3:(i+1)*3]:
                region += line[j*3:(j+1)*3]

            if sorted(region) != correct:
                return False

    
    return True



def valid_solution_set(board):
    valid = set(range(1, 10))

    for row in board:
        if set(row) != valid:
            return False

    for col in [[row[i] for row in board] for i in range(9)]:
        if set(col) != valid:
            return False

    for x in range(3):
        for y in range(3):
            if set(sum([row[x*3:(x+1)*3] for row in board[y*3:(y+1)*3]], [])) != valid:
                return False

    return True