Quick Overview

Validate a partially filled Sudoku board by checking every row, column, and three-by-three box for duplicate digits. The prompt distinguishes validity from solvability and defines empty-cell and fixed-board representations for a deterministic Boolean result.

Validate a Partially Filled Sudoku Board

Company: Verkada

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

# Validate a Partially Filled Sudoku Board You are given a partially filled `9 x 9` Sudoku board. Each cell is either a digit from `1` through `9` or `.` for an empty cell. Implement: ```text isValidSudoku(board) -> boolean ``` Return `true` exactly when the filled cells satisfy all three rules: - No digit appears more than once in any row. - No digit appears more than once in any column. - No digit appears more than once in any of the nine `3 x 3` boxes. Only validate the cells already filled. The board does not need to be solvable or complete. `board` is represented as a list of nine strings, each containing exactly nine valid cell characters. ## Constraints - `board.length == 9` - `board[i].length == 9` - Every character is `.` or a digit from `1` through `9`. ## Examples ### Example 1 ```text board = [ "53..7....", "6..195...", ".98....6.", "8...6...3", "4..8.3..1", "7...2...6", ".6....28.", "...419..5", "....8..79" ] output = true ``` No filled digit is repeated within a row, column, or box. ### Example 2 ```text board = [ "83..7....", "6..195...", ".98....6.", "8...6...3", "4..8.3..1", "7...2...6", ".6....28.", "...419..5", "....8..79" ] output = false ``` The digit `8` appears twice in the top-left `3 x 3` box.

Overview: Validate a partially filled Sudoku board by checking every row, column, and three-by-three box for duplicate digits. The prompt distinguishes validity from solvability and defines empty-cell and fixed-board representations for a deterministic Boolean result.

Read the full Verkada Software Engineer interview experience this question came from

Implement isValidSudoku(board) for a 9 x 9 board represented by nine strings of nine characters. Each character is '.' or a digit '1' through '9'. Return true exactly when no filled digit is repeated in any row, column, or 3 x 3 box. Validate only filled cells; the board need not be complete or solvable.

Constraints

  • board.length == 9
  • board[i].length == 9
  • Every character is '.' or a digit from '1' through '9'.
  • Only filled cells are validated; completeness and solvability are not required.

Examples

Input: (['.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........'],)

Expected Output: True

Explanation: An entirely empty board has no duplicate filled digit.

Input: (['53..7....', '6..195...', '.98....6.', '8...6...3', '4..8.3..1', '7...2...6', '.6....28.', '...419..5', '....8..79'],)

Expected Output: True

Explanation: The first source example satisfies all three uniqueness rules.

Hints

  1. Track seen digits separately for each row, each column, and each box.
  2. Map cell (row, column) to box (row // 3) * 3 + column // 3.

Loading coding console...

Show the approach

Approach

Scan every filled cell once. Three 9-by-9 boolean tables record whether a digit has appeared in its row, column, or box. The box index is (row / 3) * 3 + column / 3. If any corresponding flag is already set, the board violates a rule; otherwise mark all three flags and continue. Empty cells do not affect the state.

Time complexity:
O(81), which is O(1) for the fixed 9 x 9 board.
Space complexity:
O(81), which is O(1) auxiliary space for fixed-size tracking tables.