This post is completed by 1 user

  • 0
Add to List
Medium

488. Check if given sudoku is valid or not

Problem: Given a filled sudoku, write a program to check if sudoku is valid or following all of its rules.

SUDOKU rules: 

  • Each column contains all of the digits from 1 to 9 only once.
  • Each row contains all of the digits from 1 to 9 only once.
  • Each of the nine 3×3 sub-grid contains all of the digits from 1 to 9 only once.

Approach:

If we go by the rules of sudoku, we need a function for each rule (row, column and 3x3 matrix). Each function will validate whether all numbers from 1 to 9 are present and there are no duplicates present. There are 9 rows, 9 columns and 9 3x3 matrix, we will validate each of those. 

See the code below for more understanding.

Output:

Given SUDOKU is valid