Sudoku Solution Checker
InterviewTime limit5sMemory limit512 MB
Check whether each completed N-squared by N-squared grid has every row, column, and N by N block holding 1 to N-squared exactly once.
- Level
Easy3 of 10
- Topics
- Matrix, Hash map, Implementation
- Solved
- No attempts yet
Problem
Sudoku is a single player number puzzle. You fill a 9x9 grid with digits so that every row, every column, and each of the nine non-overlapping 3x3 sub-matrices holds each digit from 1 to 9 exactly once. The grid starts out partially filled and usually has one solution.


You are given a completed Sudoku grid of size . Decide whether it is a valid solution. A valid solution meets all three rules below.
- Every row holds each number from 1 to exactly once.
- Every column holds each number from 1 to exactly once.
- Split the grid into non-overlapping sub-matrices. Every sub-matrix holds each number from 1 to exactly once.
Uniqueness of the puzzle does not matter here. Only check whether the given grid is a valid solution.
Input
The first line holds the number of test cases . test cases follow. Each test case starts with an integer . The next lines describe a completed Sudoku grid, and each line holds exactly integers. Every integer in the input is positive and smaller than 1000.
Limits
Output
For each test case print one line in the form Case #x: y, where x is the test case number starting from 1 and y is Yes if the grid is a valid solution or No if it is not. The judge is case sensitive, so yes and no are not accepted.