Solve a Sudoku
grid is a list of nine strings of nine characters, digits 1-9 or . for empty, with
exactly one solution. Write solve(grid) that returns the solved grid in the same format.
solve(["53..7....", "6..195...", ".98....6.", "8...6...3", "4..8.3..1", "7...2...6", ".6....28.", "...419..5", "....8..79"])
-> ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"]
Backtracking cell by cell: for an empty cell, try each digit not already in its row, column or 3x3 box; recurse; undo. Keep three lists of sets so the legality check is constant time.
def solve(grid):
...