← Verkada Interview InsightsSoftware Engineer
The row and column checks are easy enough, but the box part trips people up if they haven't seen it before.
Clarify the problem constraints and edge cases, then propose a solution using hash sets to track seen digits in each row, column, and 3x3 sub-box. Iterate through each cell, skipping empty cells, and check for duplicates; return false immediately if a duplicate is found, otherwise true after full traversal.
Pro tip: Mention that you can optimize space by using bitmasks instead of hash sets, and discuss the trade-offs between clarity and performance. Also, emphasize that early termination on duplicate detection can significantly speed up validation for invalid boards.
Confirm that the board is 9x9, digits are '1'-'9' or '.', and that we only validate the current state, not solvability. Discuss handling of invalid characters or board sizes if applicable.
Decide on using hash sets (or boolean arrays/bitmasks) for each row, column, and sub-box to track seen digits. Explain why this allows O(1) duplicate checks.
Loop through each cell; if it's not empty, compute its sub-box index (row/3, col/3) and check if the digit already exists in the corresponding row, column, or sub-box set. If duplicate, return false.
After processing all cells, return true. State that time complexity is O(1) since the board size is fixed (81 cells), and space complexity is O(1) as well (at most 9 sets of size 9).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.