Thumbtack Interview Question: Given an 2D array that repres... | Glassdoor

Interview Question

Software Engineer Interview(Student Candidate)

Given an 2D array that represents a Sudoku board, check

  that it is in a valid configuration.
Answer

Interview Answer

1 Answer

1

// 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;
}

Joseph on Dec 27, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.