Asked inPracto,

Sudoku Solver Problem Statement

You are provided with a 9x9 sudoku grid. Your objective is to solve the sudoku and deliver the complete solution.

Description:

A sudoku puzzle is a 9x9 grid, divided into nine 3x3 subgrids, where the player needs to fill the grid following these conditions:

  • Every number from 1 to 9 should appear exactly once in each row.
  • Every number from 1 to 9 should appear exactly once in each column.
  • Every number from 1 to 9 should appear exactly once in each 3x3 subgrid.

Example:

Consider the following sudoku example:

example1

The solved version would be:

solution

Input:

First nine lines of input contain N (=9) space-separated integers, representing elements of a 2D array ARR.

Output:

For each test case, return the solution of the sudoku.

Example:

Input:

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

Output:

5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9

Constraints:

  • N = 9
  • 0 <= ARR[i][j] <= 9
  • Time Limit: 1 second

Note:

You are not required to print anything; it has already been taken care of. Implement the given function; the system will verify your solution and output ‘CORRECT SOLUTION’ if your solution to the sudoku is correct, ‘INCORRECT SOLUTION’ otherwise.

Be the first one to answer
Add answer anonymously...
Practo Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter