FastPrepValid Sudoku
Problem · Array

Valid Sudoku

Learn this problem
MediumVerkada logoVerkadaFULLTIMEPHONE SCREEN

Problem statement

Determine whether a partially filled 9 x 9 Sudoku board is valid.

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. Empty cells contain ..

Validate only the filled cells; 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 filled row, column, or sub-box contains a repeated digit.

Example 2

board = [["8","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 = false

The upper-left sub-box contains two cells with digit 8.

Constraints

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

More Verkada 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