C++ Program to back track
C++ Program to back track
#include <iostream>
#include <vector>
if (mat[row][x] == num)
return false;
if (mat[x][col] == num)
return false;
return false;
return true;
int n = mat.size();
return true;
if (col == n) {
row++;
col = 0;
if (mat[row][col] != 0)
mat[row][col] = num;
return true;
mat[row][col] = 0;
return false;
solveSudokuRec(mat, 0, 0);
int main() {
vector<vector<int>> mat = {
{3, 0, 6, 5, 0, 8, 4, 0, 0},
{5, 2, 0, 0, 0, 0, 0, 0, 0},
{0, 8, 7, 0, 0, 0, 0, 3, 1},
{0, 0, 3, 0, 1, 0, 0, 8, 0},
{9, 0, 0, 8, 6, 3, 0, 0, 5},
{0, 5, 0, 0, 9, 0, 6, 0, 0},
{1, 3, 0, 0, 0, 0, 2, 5, 0},
{0, 0, 0, 0, 0, 0, 0, 7, 4},
{0, 0, 5, 2, 0, 6, 3, 0, 0}};
solveSudoku(mat);
return 0;