FastPrepSudoku Board Validation
Problem · Array

Sudoku Board Validation

Learn this problem
MediumConfluent logoConfluentFULLTIMEONSITE INTERVIEW

Problem statement

Given a partially filled 9 x 9 Sudoku board, return true if every filled cell obeys the Sudoku rules and false otherwise.

Each row, each column, and each of the nine 3 x 3 sub-boxes may contain each digit from 1 through 9 at most once. An empty cell contains '.'.

Check only whether the filled cells are consistent. The board does not need to be solvable.

Function

isValidSudoku(board: char[][]) → boolean

Examples

Example 1

board = [["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"]]return = true

No row, column, or sub-box repeats a filled digit.

Example 2

board = [["5","3",".",".","7",".",".",".","5"],["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"]]return = false

The first row contains digit 5 twice.

Constraints

  • board.length == 9.
  • board[i].length == 9.
  • Every cell is '.' or a digit from '1' through '9'.

More Confluent problems

drafts saved locally
public boolean isValidSudoku(char[][] board) {
    // write your code here
}
board[["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"]]
expectedtrue
checking account