Sudoku Validity Problem Statement
You are provided with a 9 x 9 2D matrix MATRIX
containing digits (1-9) and empty cells indicated by 0.
Your task is to determine if there exists a method to fill all empty cells with digits (1-9) such that the resulting matrix is a valid Sudoku solution.
A valid Sudoku solution must meet the following criteria:
- Each digit from 1 to 9 must appear exactly once in each row.
- Each digit from 1 to 9 must appear exactly once in each column.
- Each digit from 1 to 9 must appear exactly once in each of the nine 3 x 3 sub-matrices within the main matrix.
Input:
The first line contains an integer 'T', the number of test cases. For each test case, 9 lines follow, each containing 9 space-separated integers representing a row in the matrix.
Output:
For each test case, output "yes" if a valid Sudoku solution exists, or "no" if it does not. Outputs should be in lowercase.
Example:
Input:
2
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 9
8 3 5 4 1 9 2 7 6
7 2 6 8 5 0 4 9 1
5 9 1 7 3 2 0 6 8
4 6 8 2 7 3 5 1 9
6 7 2 3 9 1 8 5 4
3 8 9 5 6 4 1 2 7
1 5 4 9 8 7 6 3 2
Output:
yes
no
- The matrix always contains at least one empty cell.
- The initial matrix is consistent with Sudoku rules.
Constraints:
- 1 ≤ T ≤ 5
- N = 9
- 0 ≤ MATRIX[i][j] ≤ 9
- Time Limit: 1 sec

AnswerBot
4mo
Check if a valid Sudoku solution exists for a given 9x9 matrix with empty cells.
Iterate through each row, column, and sub-matrix to ensure all digits from 1 to 9 appear exactly once.
Use sets to keep t...read more
Help your peers!
Add answer anonymously...
JPMorgan Chase & Co. Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Count Subarrays with Given XOR Problem Statement You are given an array of integ...read more
A Software Developer Intern was asked Q. Kth Largest Number Problem Statement You are given a continuous stream of number...read more
A Software Developer Intern was asked Q. Stack using Two Queues Problem Statement Develop a Stack Data Structure to store...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Count Subarrays with Given XOR Problem Statement You are given an array of integ...read more
A Software Developer Intern was asked Q2. Kth Largest Number Problem Statement You are given a continuous stream of number...read more
A Software Developer Intern was asked Q3. Stack using Two Queues Problem Statement Develop a Stack Data Structure to store...read more
>
JPMorgan Chase & Co. Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

