Sudoku Solver
Understand and solve the interview question "Sudoku Solver".
We'll cover the following...
Description
Write a program to solve Sudoku by filling the empty cells. We will be given a 2D array representing a Sudoku puzzle. For a correct solution each of the digits 1-9 must only occur once in each:
- Row
- Column
- Nine 3x3 sub-boxes of the grid
Let us take a look at an example:
To solve the puzzle, we will only fill the empty cells. Empty cells are represented by a ‘.’. The array will be passed by reference, so we will not need to return it after solving the puzzle.
Coding exercise
object Solution {def solveSudoku(board:Array[Array[Char]]) {// Write code hereprintln("\n")board.foreach(x=> println("[" + x.mkString(",") + "]"))println("\n")}}
Sudoku Solver
Solution
While solving Sudoku, we will have to take care of two things. First, we place a number at an empty place. The number must not be present in that row, column, or sub-box. So, we will use constrained programming to keep track of which ...
Access this course and 1400+ top-rated courses and projects.