Validate a Partially Filled Sudoku Board Before Saving a Puzzle
Last updated: November 29, 2026
Quick Overview
Given a 9x9 grid of digits '1' to '9' and '.' for empty cells, return True if no row, column or 3x3 box contains a repeated digit. The board does not need to be solvable.
0
0
0 solved
Given a 9x9 grid of digits '1' to '9' and '.' for empty cells, return True if no row, column or 3x3 box contains a repeated digit. The board does not need to be solvable.
Framed as server-side validation for a puzzle feature in Google Search's built-in games. The interviewer is looking at how cleanly you index the 3x3 boxes and whether you use hash sets (or bitmasks) to check all constraints in one pass.
What the Interviewer Expects
- Checks rows, columns, and boxes in a single pass
- Computes the box index as (r // 3) * 3 + c // 3
- Uses sets or bitmasks per constraint
- Skips empty cells
- Clarifies that validity does not imply solvability
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Use bitmasks instead of sets; what is the benefit?
- Extend to an N^2 by N^2 board.
- Now actually solve the puzzle; how do you prune the backtracking?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
board, a list of 9 lists of 9 single-character strings. - Output: True if every filled digit is unique within its row, its column, and its 3x3 sub-box.
- Empty cells ('.') are ignored. Solv...
High-Level Design
Keep 9 sets for rows, 9 for columns, and 9 for boxes. For each filled cell at (r, c) with digit d, compute b = (r // 3) * 3 + c // 3. If d is already in rows[r], cols[c], or boxes[b], the boar...