Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

​

Solution: Sudoku Solver

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 3 years ago

One would expect that the expected result to be the solution of the given sudoku. Why is that the test cases expect a True or False answer? What is the question then?

A

Anonymous

· 3 years ago

For the isValid Function, can't you just put it like this instead of having a for loop in it?

def isValid(self, board, row, col, num): '''return True if Valid and False if not valid''' ### NEW VERSION ### - this passes the tests # Check if in ROW if board[row][:] == num: return False # Check if in COL if board[:][col] == num: return False # Check if in 3 x 3 GRID if (board[(row//3)*3 + row//3][(col//3)*3 + col%3] == num): return False return True ### ORIGINAL VERSION ### for x in range(9): # Check if in ROW if board[row][x] == num: return False # Check if in COL if board[x][col] == num: return False # Check if in 3 x 3 GRID if (board[(row//3)*3 + x//3][(col//3)*3 + x%3] == num):
Show 1 reply

Reading Progress

0%


Vote for new content