Unicorns VO Interview Question: Determine if a 9 x 9 Sudoku Board Is Valid

17 Views
No Comments

Determine if a 9 x 9 Sudoku board is valid.

Only the filled cells need to be validated according to the following rules:

  • Each row must contain the digits 1-9 without repetition.
  • Each column must contain the digits 1-9 without repetition.
  • Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.

Note:

  • A Sudoku board (partially filled) could be valid but is not necessarily solvable.
  • Only the filled cells need to be validated according to the mentioned rules.

This problem asks you to verify whether a partially filled 9 x 9 Sudoku board is valid. You only need to check the filled cells, ensuring there are no repeated digits in any row, column, or 3 x 3 sub-box. The board does not need to be solvable, only consistent with the Sudoku rules so far. A common solution is to scan the grid once while using sets or boolean markers for rows, columns, and boxes, and return false as soon as a duplicate is found.

END
 0