Sudoku Rules Check
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
Each row, each column and each of the four 2 by 2 boxes holds the 1 and the 4 once.
Example 2
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
1 <= height, widthandheight * width <= 9len(board) == nandlen(board[r]) == n, wheren = height * width0 <= board[r][c] <= n
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Turn Every RingMedium
- Zigzag DiagonalsMedium
- Darken the BoardHard
- Flags in OrderHard
- Island ShapesHard
- Largest Island After One FillHard
- Last Dry CrossingHard
- Longest ClimbHard