#C8341. Valid Grid Checker
Valid Grid Checker
Valid Grid Checker
Problem Statement:
Given an ( n \times n ) grid where each cell contains an integer (either 0 or a digit from 1 to 9), determine whether the grid is valid. A grid is valid if every non-zero digit appears at most once in each row and at most once in each column. Zeros represent empty cells and should be ignored during the check.
You will be given multiple test cases. For each test case, output True
if the grid satisfies the validity condition; otherwise, output False
.
The constraints ensure that the grid size is manageable and the digits are within the range [0,9].
inputFormat
Input Format:
The first line contains an integer (T) (the number of test cases). For each test case, the first line contains an integer (n) representing the size of the grid. The next (n) lines each contain (n) space-separated integers. Each integer is either 0 (representing an empty cell) or a digit from 1 to 9.
outputFormat
Output Format:
For each test case, print a single line containing either True
or False
indicating whether the grid is valid.## sample
1
4
5 3 0 0
6 0 0 0
0 9 8 0
0 0 0 1
True
</p>