← Verkada Inc. Interview Insights
I went straight for sets and tracked each row, column, and box in a single pass.
Use a single pass through the board, maintaining hash sets for each row, column, and 3x3 sub-box to detect duplicates. For each filled cell, check if the digit already exists in the corresponding row, column, or box; if so, return false. Otherwise, add the digit to all three sets and continue. Return true if no duplicates are found.
Pro tip: Clarify with the interviewer whether the board is guaranteed to be 9x9 and whether empty cells are always represented by '.', as this affects input validation. Also, mention that you can optimize space by using bitmasks instead of sets, which is a common follow-up.
Confirm that the board is 9x9, empty cells are '.', and only filled cells need validation. Ask if the board is guaranteed to be valid in terms of size and characters.
Decide to use hash sets for rows, columns, and boxes, or bitmasks for space efficiency. Explain the trade-offs.
Loop over each cell. If the cell is not '.', compute the box index (row/3)*3 + col/3. Check if the digit exists in the corresponding row, column, or box set.
If a duplicate is found, return false immediately. Otherwise, add the digit to the row, column, and box sets.
After the loop, return true. Mention that time complexity is O(1) since the board size is fixed (81 cells), and space complexity is O(1) as well.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.