← Amazon questions

Valid Sudoku

Filed under Amazon

Free read 3 of 3

Use three arrays of sets (or boolean arrays) to track seen numbers for rows, columns, and 3x3 blocks.

The question

Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the rules: each row, column, and 3x3 sub-box must contain digits 1-9 without repetition.

Constraints

  • Board is always 9x9.
  • Empty cells are represented by '.'
  • Time complexity O(1) since board size is fixed.

Examples

Input
9x9 grid
Output
True/False
Why
Check sets for each row, column, and block.

Approach

  1. Use three arrays of sets (or boolean arrays) to track seen numbers for rows, columns, and 3x3 blocks.

Tips

  • What they are testing: Test an empty board and a full board with one duplicate.
  • Common mistake: Using a single set for the whole board instead of separate sets for rows, columns, and boxes.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.