Question bankPricingSign in

Valid Sudoku

Arrays & HashingEasy1:00

Given a 9x9 Sudoku board, determine if it is valid. A valid board means each row, each column, and each of the nine 3x3 sub-boxes contains the digits 1-9 without repetition. The board may be partially filled, with empty cells represented by a dot.

For example, a board where row 0 contains [5, 3, ., ., 7, ., ., ., .] and row 1 contains [6, ., ., 1, 9, 5, ., ., .] would need to be checked for duplicates across all rows, columns, and sub-boxes.

Explain your approach to validating the board and analyze the time and space complexity.

How to approach it

  • Hint 1

    You need to check three things independently: rows, columns, and 3x3 sub-boxes.

  • Hint 2

    A hash set for each row, column, and sub-box can track which digits have appeared.

  • Hint 3

    The key insight for sub-boxes: the box index for cell (r, c) can be computed as (r // 3) * 3 + (c // 3).

Ready to answer it out loud?

Record your answer in 1:00 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.