Coding problem
Fill in a sudoku
The task
A puzzle app checks every sudoku before it publishes it, by solving it on the server.
Complete SolveSudoku(char[][] board). The board has 9 rows of 9 cells; each cell holds a digit from '1' to '9' or '.' for an empty cell. Return a new, solved board in which every row, every column and every 3 × 3 box holds the digits 1 to 9 once each, keeping every given digit. Do not fill in the caller's board. Throw ArgumentException when a given digit already repeats in a row, a column or a box. Every board in the tests that has no repeated digit has exactly one solution.
Signature
public static char[][] SolveSudoku(char[][] board)
Examples
- board
...2..96. / ...45.7.. / 827.6.... / ......5.. / 47592.... / 3.....829 / ....9...5 / .53.....6 / 9.251.4..→541287963 / 639451782 / 827369154 / 298136547 / 475928631 / 316745829 / 784692315 / 153874296 / 962513478. The only solution; rows are shown top to bottom. - board
11......., then eight empty rows→throws ArgumentException. The digit 1 repeats in the first row.
Limits: Three puzzles with 26 to 30 given digits, and a full board. Each test must finish within the 10 s limit of the whole run.
The tests check: three puzzles solved, that your method leaves the caller's board unchanged, a board that is already solved, and a board with a repeated digit refused.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// Returns a new solved board (the caller's board is not changed); throws ArgumentException for a repeated digit.
public static char[][] SolveSudoku(char[][] board)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.