FunctionRacerProblemsRace

Sudoku Rules Check

MediumGridsPython, JavaScript, TypeScript, Java, C++

board is a partly filled grid for a Sudoku-style puzzle with n rows and n columns, where n = height * width, given as a list of rows. 0 marks an empty cell and every other cell holds a digit from 1 to n. The board is cut into boxes that are height cells tall and width cells wide, starting from the top-left corner. Return True if no digit appears twice in any row, in any column or in any box, and False otherwise. Empty cells never break a rule, and the board does not have to be solvable. Do not change board.

Example 1

board [[1,0,0,4],[0,4,1,0],[0,1,4,0],[4,0,0,1]]
height 2
width 2
returns true

Each row, each column and each of the four 2 by 2 boxes holds the 1 and the 4 once.

Example 2

board [[1,2,3,0,0,0],[0,0,1,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]]
height 2
width 3
returns false

The 1 in row 1, column 2 is alone in its row and its column, but it shares the top-left box (rows 0 and 1, columns 0 to 2) with the 1 in the corner.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems