Pergunta de entrevista da empresa Thumbtack

Given an 2D array that represents a Sudoku board, check that it is in a valid configuration.

Resposta da entrevista

Sigiloso

27 de dez. de 2015

// Recently asked the same thing by Mixpanel. int is_valid_solution(char grid[]) { int valid[9] = {}; const int offset = 9; int cell = 0; for (int i=0; i 0) && (cell < 10))) return 0; valid[cell - 1] = 1; } if (((j+1) % 3) == 0) { // a grid is complete. test valid here; for (int z=0; z < 9; z++) { if (valid[z] != 1) return 0; valid[z] = 0; } } } } return 1; }

1