Valid Sudoku

Advanced

Welcome to the Sudoku Palace, young code-master! Here lies your quest, a mission of wits and logic. Your task is to build a wise function that can determine the authenticity of a Sudoku board. A Sudoku board is like a puzzle grid, composed of nine 3x3 smaller grids. Each row, each column, and each tiny 3x3 grid must have all the digits from 1 to 9 without repetition.

To complete this quest, you must craft the magical function is_valid_sudoku, which will take a grid of numbers (a list of lists) and return True if the numbers on it form a valid Sudoku configuration, or False if they don’t.

Remember, zeros (0) on the board mean empty spaces and these do not affect the validity.

Here's an example of how your mighty function might be tested:

valid_board = [ [5, 3, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9] ] invalid_board = [ [5, 5, 0, 0, 7, 0, 0, 0, 0], [6, 0, 0, 1, 9, 5, 0, 0, 0], [0, 9, 8, 0, 0, 0, 0, 6, 0], [8, 0, 0, 0, 6, 0, 0, 0, 3], [4, 0, 0, 8, 0, 3, 0, 0, 1], [7, 0, 0, 0, 2, 0, 0, 0, 6], [0, 6, 0, 0, 0, 0, 2, 8, 0], [0, 0, 0, 4, 1, 9, 0, 0, 5], [0, 0, 0, 0, 8, 0, 0, 7, 9] ] print(is_valid_sudoku(valid_board)) # Should return True print(is_valid_sudoku(invalid_board)) # Should return False

Good luck on your journey, and may your code run without bugs!

Geek
Inputs

Arg 1:

[[5,3,0,0,7,0,0,0,0],[6,0,0,1,9,5,0,0,0],[0,9,8,0,0,0,0,6,0],[8,0,0,0,6,0,0,0,3],[4,0,0,8,0,3,0,0,1],[7,0,0,0,2,0,0,0,6],[0,6,0,0,0,0,2,8,0],[0,0,0,4,1,9,0,0,5],[0,0,0,0,8,0,0,7,9]]
Expected Output
true
Actual Output
Valid Sudoku [advanced] | Coding for Kids