PIXELBANKv9.1.0
Menu

Determine if a 9x9 Sudoku board is valid. Only filled cells need to be validated: each row, column, and 3x3 box must contain digits 1-9 without repetition.

Input: 9 rows, each with 9 comma-separated values ('.' for empty).

Example:

Input:
5,3,.,.,7,.,.,.,.
6,.,.,1,9,5,.,.,.
.,9,8,.,.,.,.,6,.
8,.,.,.,6,.,.,.,3
4,.,.,8,.,3,.,.,1
7,.,.,.,2,.,.,.,6
.,6,.,.,.,.,2,8,.
.,.,.,4,1,9,.,.,5
.,.,.,.,8,.,.,7,9
Output:
True
Reasoning:
  • The input is a 9x9 Sudoku board represented as 9 rows of comma-separated values, where '.' denotes an empty cell.
  • We iterate over each row, column, and 3x3 box to check for duplicate digits (1-9), ignoring empty cells ('.').
  • For each row, column, and box, we verify that all filled cells contain unique digits, i.e., no digit appears more than once: count(digits)=count(unique_digits)count(digits) = count(unique\_digits).
  • Since no duplicates are found in any row, column, or box, the Sudoku board is valid, resulting in an output of True.

Constraints:

  • board.length == 9
  • board[i].length == 9
  • board[i][j] is a digit or '.'
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Valid Sudoku - Medium | PixelBank