Google Interview Question
1,225 Interview Reviews |
Back to all Google Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Engineer at Google:
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (7)
0 of 4 people found this helpful
you need 27 variables (int). And based on the coordinates in the sudoku table you update for each value 3 of these by setting the corresponding bit to 1.
At the end in order to check the validity of the solution, it just needs all those 27 variables to be 111111111(2). If not, then you have no solution!
Implementing is straightforward!
Helpful Answer?
Yes |
No
Inappropriate?
@Gabriel, I don't understand your solution, can you make it clearer?
Helpful Answer?
Yes |
No
Inappropriate?
1 of 1 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
Helpful Answer?
Yes |
No
Inappropriate?
Helpful Answer?
Yes |
No
Inappropriate?
results = [0] * 27
for i, v in enumerate(grid):
for j, w in enumerate(v):
box = j/3 + (i/3)*3
results[i] |= 1 << w-1
results[9+j] |= 1 << w-1
results[18+box] |= 1 << w-1
return len([1 for i in results if i == 511]) == 27 # 511 == 111111111
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 1 people found this helpful
by Interview Candidate: