<p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>

<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>

<ol>
	<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
	<li>Each of the digits <code>1-9</code> must occur exactly once in each column.</li>
	<li>Each of the digits <code>1-9</code> must occur exactly once in each of the 9 <code>3x3</code> sub-boxes of the grid.</li>
</ol>

<p>The <code>&#39;.&#39;</code> character indicates empty cells.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Sudoku-by-L2G-20050714.svg/250px-Sudoku-by-L2G-20050714.svg.png" style="height:250px; width:250px" />
<pre>
<strong>Input:</strong> board = [[&quot;5&quot;,&quot;3&quot;,&quot;.&quot;,&quot;.&quot;,&quot;7&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;6&quot;,&quot;.&quot;,&quot;.&quot;,&quot;1&quot;,&quot;9&quot;,&quot;5&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;9&quot;,&quot;8&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;6&quot;,&quot;.&quot;],[&quot;8&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;6&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;3&quot;],[&quot;4&quot;,&quot;.&quot;,&quot;.&quot;,&quot;8&quot;,&quot;.&quot;,&quot;3&quot;,&quot;.&quot;,&quot;.&quot;,&quot;1&quot;],[&quot;7&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;2&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;6&quot;],[&quot;.&quot;,&quot;6&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;2&quot;,&quot;8&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;4&quot;,&quot;1&quot;,&quot;9&quot;,&quot;.&quot;,&quot;.&quot;,&quot;5&quot;],[&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;.&quot;,&quot;8&quot;,&quot;.&quot;,&quot;.&quot;,&quot;7&quot;,&quot;9&quot;]]
<strong>Output:</strong> [[&quot;5&quot;,&quot;3&quot;,&quot;4&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;1&quot;,&quot;2&quot;],[&quot;6&quot;,&quot;7&quot;,&quot;2&quot;,&quot;1&quot;,&quot;9&quot;,&quot;5&quot;,&quot;3&quot;,&quot;4&quot;,&quot;8&quot;],[&quot;1&quot;,&quot;9&quot;,&quot;8&quot;,&quot;3&quot;,&quot;4&quot;,&quot;2&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;],[&quot;8&quot;,&quot;5&quot;,&quot;9&quot;,&quot;7&quot;,&quot;6&quot;,&quot;1&quot;,&quot;4&quot;,&quot;2&quot;,&quot;3&quot;],[&quot;4&quot;,&quot;2&quot;,&quot;6&quot;,&quot;8&quot;,&quot;5&quot;,&quot;3&quot;,&quot;7&quot;,&quot;9&quot;,&quot;1&quot;],[&quot;7&quot;,&quot;1&quot;,&quot;3&quot;,&quot;9&quot;,&quot;2&quot;,&quot;4&quot;,&quot;8&quot;,&quot;5&quot;,&quot;6&quot;],[&quot;9&quot;,&quot;6&quot;,&quot;1&quot;,&quot;5&quot;,&quot;3&quot;,&quot;7&quot;,&quot;2&quot;,&quot;8&quot;,&quot;4&quot;],[&quot;2&quot;,&quot;8&quot;,&quot;7&quot;,&quot;4&quot;,&quot;1&quot;,&quot;9&quot;,&quot;6&quot;,&quot;3&quot;,&quot;5&quot;],[&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;2&quot;,&quot;8&quot;,&quot;6&quot;,&quot;1&quot;,&quot;7&quot;,&quot;9&quot;]]
<strong>Explanation:</strong>&nbsp;The input board is shown above and the only valid solution is shown below:

<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Sudoku-by-L2G-20050714_solution.svg/250px-Sudoku-by-L2G-20050714_solution.svg.png" style="height:250px; width:250px" />
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>board.length == 9</code></li>
	<li><code>board[i].length == 9</code></li>
	<li><code>board[i][j]</code> is a digit or <code>&#39;.&#39;</code>.</li>
	<li>It is <strong>guaranteed</strong> that the input board has only one solution.</li>
</ul>

class Solution {
public:

    vector<vector<char>> trymat(queue<pair<int,int>> blanks,vector<vector<char>> board,vector<vector<int>> vert,vector<vector<int>> hor, vector<vector<int>> squares){

        // cout << "hor"<<endl;
        //  for(int i =0; i <board.size();i++){
        //     for(int j =0; j<board.size();j++){
        //         cout << board[i][j] << ",";
        //     }cout <<endl;}


        if(blanks.size()==0)return board;
        auto here =  blanks.front();
        blanks.pop();
        int i = here.first;
        int j = here.second;
        for(int k = 0;k<9;k++){
            if(vert[j][k] != 1 && hor[i][k] !=1 &&  squares[j/3+(i/3)*3][k] != 1){
                vert[j][k] = 1; 
                hor[i][k] =1 ;
                squares[j/3+(i/3)*3][k] = 1;
                // hor[i][9]++;
                // vert[j][9]++;
                // squares[j/3+(i/3)*3][9]++;

                board[i][j] = k+'0'+1;
                vector<vector<char>> result = trymat(blanks,board,vert,hor, squares);
                if(result.size()==board.size()){
                    return result;
                }
                vert[j][k] =0;
                hor[i][k] =0 ;
                squares[j/3+(i/3)*3][k] = 0;
            }
            // cout << k+1 <<" ";
            // if(vert[j][k] == 1 ){
            //     cout << "vert no match"<<endl;
            // }
            // if(hor[i][k] ==1 ){
            //     cout << "hor no match"<<endl;
            // }
            // if( squares[j/3+(i/3)*3][k] == 1){
            //     cout << "squares no match"<<endl;
            // }
            // cout <<endl;
        }
        vector<vector<char>> empty;
        return empty;
    }
    void solveSudoku(vector<vector<char>>& board) {
        vector<vector<int>> vert(9,vector<int>(10,0));
        vector<vector<int>> hor(9,vector<int>(10,0));
        vector<vector<int>> squares(9,vector<int>(10,0));
        queue<pair<int,int>> blanks;
        for(int i =0; i < board.size();i++){
            for(int j =0; j< board.size();j++){
                if(board[i][j] != '.'){
                    hor[i][board[i][j] -'0'-1] =  1;
                    vert[j][board[i][j] -'0'-1] =  1;
                    squares[j/3+(i/3)*3][board[i][j] -'0'-1] =  1;
                    hor[i][9]++;
                    vert[j][9]++;
                    squares[j/3+(i/3)*3][9]++;
                }
                else{
                    blanks.push({i,j});
                }
            }
        }

        board = trymat(blanks,board,vert,hor, squares);
         for(int i =0; i < board.size();i++){
            for(int j =0; j< board.size();j++){
                 cout << board[i][j] << ",";
            }cout <<endl;}
        // cout << "vert"<<endl;
        //  for(int i =0; i < board.size();i++){
        //     for(int j =0; j<= board.size();j++){
        //         cout << vert[i][j] << ",";
        //     }cout <<endl;}
        // cout << "hor"<<endl;
        //  for(int i =0; i <board.size();i++){
        //     for(int j =0; j<=board.size();j++){
        //         cout << hor[i][j] << ",";
        //     }cout <<endl;}
        // cout << "squares"<<endl;
        //  for(int i =0; i <board.size();i++){
        //     for(int j =0; j<=board.size();j++){
        //         cout << squares[i][j] << ",";
        //     }cout <<endl;}
    }
};
213334