Fill In a 9×9 Sudoku Puzzle to Completion

Implement solveSudokuBoard

Given a partially filled 9×9 Sudoku board, fill in every empty cell so that each digit 1–9 appears exactly once in every row, every column, and every 3×3 box. The puzzle is guaranteed to have exactly one valid completion. Scanning the whole board from the start to find the next empty cell, and checking a candidate digit by walking the entire row, column, and box arrays, both work — but repeat information the search already had. Passing the next position down directly, and maintaining a table of which digits are already used in each row, column, and box, turns both of those repeated derivations into a single lookup: the exact same tree of choices gets explored, just without re-deriving facts about the board that hadn't changed.

Example 1:

Input: board = [".39852746","852746139","746139852","591428367","428367591","367591428","973215684","215684973","684973215"]

Output: ["139852746","852746139","746139852","591428367","428367591","367591428","973215684","215684973","684973215"]

Example 2:

Input: board = [".398.274.","852746139","746139852","591428367",".283.759.","367591428","973215684","215684973",".849.321."]

Output: ["139852746","852746139","746139852","591428367","428367591","367591428","973215684","215684973","684973215"]

Example 3:

Input: board = [".39.52.46","8.27.61.9","746139852",".91.28.67","4.83.75.1","367591428",".73.15.84","2.56.49.3","684973215"]

Output: ["139852746","852746139","746139852","591428367","428367591","367591428","973215684","215684973","684973215"]

+ 2 hidden test cases run on Submit.

Constraints:

  • The board is always exactly 9 rows of 9 characters, each either a digit '1'–'9' or '.' for an empty cell
  • The given puzzle always has exactly one valid completion
  • A completed board must have each digit 1–9 appear exactly once in every row, every column, and every 3×3 box

board =

[".39852746", "852746139", "746139852", "591428367", "428367591", "367591428", "973215684", "215684973", "684973215"]