Question presented to candidate: "Build a playable Sudoku board. Show a 9 by 9 grid with a puzzle prefilled; the given numbers cannot be edited. As the player types, highlight every cell that breaks the rules, meaning the same digit twice in a row, a column or a 3 by 3 box, and tell them when the puzzle is solved."
Requirements:
- 81 cells; givens are visually distinct and read-only.
- Only the digits 1 to 9 are accepted; typing over a cell replaces its digit; Backspace or Delete clears it.
- Live validation: every cell involved in a duplicate in its row, column or box is highlighted, givens included.
- A filled counter, a conflict counter and a "Solved" message when all 81 cells are filled with no conflicts.
- Arrow keys move between cells; the row, column and box of the focused cell are softly highlighted.
- A Clear button restores the original puzzle.
What a strong answer should cover:
- One piece of state (81 numbers) with conflicts, counts and "solved" all derived from it, recomputed with memoisation.
- An efficient conflict algorithm: walk the 27 units (9 rows, 9 columns, 9 boxes) and flag values that appear more than once, and the box index formula
floor(row / 3) * 3 + floor(col / 3). - Input sanitising (letters, 0, paste) and keeping the DOM in sync when an edit is rejected.
- Roving tabindex so the grid is one tab stop, with arrow-key navigation and labelled cells (
aria-invalidon conflicts). - Validation versus solving: rule-checking does not need the solution; a solver (backtracking) is a separate concern.
Clarifying questions expected:
- "Should we validate against the rules only, or against the known solution?"
- "Do you want pencil marks (candidate notes) or just one digit per cell?"
- "Where do puzzles come from: hard-coded, generated, or fetched?"
Code / implementation expected: Yes. A working grid with live conflict highlighting in the framework of your choice; the validation function should be plain and testable.