<p>Determine if a&nbsp;<code>9 x 9</code> Sudoku board&nbsp;is valid.&nbsp;Only the filled cells need to be validated&nbsp;<strong>according to the following rules</strong>:</p>

<ol>
	<li>Each row&nbsp;must contain the&nbsp;digits&nbsp;<code>1-9</code> without repetition.</li>
	<li>Each column must contain the digits&nbsp;<code>1-9</code>&nbsp;without repetition.</li>
	<li>Each of the nine&nbsp;<code>3 x 3</code> sub-boxes of the grid must contain the digits&nbsp;<code>1-9</code>&nbsp;without repetition.</li>
</ol>

<p><strong>Note:</strong></p>

<ul>
	<li>A Sudoku board (partially filled) could be valid but is not necessarily solvable.</li>
	<li>Only the filled cells need to be validated according to the mentioned&nbsp;rules.</li>
</ul>

<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> true
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> board = 
[[&quot;8&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> false
<strong>Explanation:</strong> Same as Example 1, except with the <strong>5</strong> in the top left corner being modified to <strong>8</strong>. Since there are two 8&#39;s in the top left 3x3 sub-box, it is invalid.
</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 <code>1-9</code> or <code>&#39;.&#39;</code>.</li>
</ul>

class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        // the size of the board
        int row = board.size();
        int column = board[0].size();

        // scan different rows
        unordered_map<char, int> row_mp1;
        for (int i = 0; i < column; i++) {
            if (board[0][i] != '.') {
                row_mp1[board[0][i]]++;
                if (row_mp1[board[0][i]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> row_mp2;
        for (int i = 0; i < column; i++) {
            if (board[1][i] != '.') {
                row_mp2[board[1][i]]++;
                if (row_mp2[board[1][i]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> row_mp3;
        for (int i = 0; i < column; i++) {
            if (board[2][i] != '.') {
                row_mp3[board[2][i]]++;
                if (row_mp3[board[2][i]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> row_mp4;
        for (int i = 0; i < column; i++) {
            if (board[3][i] != '.') {
                row_mp4[board[3][i]]++;
                if (row_mp4[board[3][i]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> row_mp5;
        for (int i = 0; i < column; i++) {
            if (board[4][i] != '.') {
                row_mp5[board[4][i]]++;
                if (row_mp5[board[4][i]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> row_mp6;
        for (int i = 0; i < column; i++) {
            if (board[5][i] != '.') {
                row_mp6[board[5][i]]++;
                if (row_mp6[board[5][i]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> row_mp7;
        for (int i = 0; i < column; i++) {
            if (board[6][i] != '.') {
                row_mp7[board[6][i]]++;
                if (row_mp7[board[6][i]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> row_mp8;
        for (int i = 0; i < column; i++) {
            if (board[7][i] != '.') {
                row_mp8[board[7][i]]++;
                if (row_mp8[board[7][i]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> row_mp9;
        for (int i = 0; i < column; i++) {
            if (board[8][i] != '.') {
                row_mp9[board[8][i]]++;
                if (row_mp9[board[8][i]] > 1) {
                    return false;
                }
            }
        }

        // scan different columns
        unordered_map<char, int> column_mp1;
        for (int i = 0; i < row; i++) {
            if (board[i][0] != '.') {
                column_mp1[board[i][0]]++;
                if (column_mp1[board[i][0]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> column_mp2;
        for (int i = 0; i < row; i++) {
            if (board[i][1] != '.') {
                column_mp2[board[i][1]]++;
                if (column_mp2[board[i][1]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> column_mp3;
        for (int i = 0; i < row; i++) {
            if (board[i][2] != '.') {
                column_mp3[board[i][2]]++;
                if (column_mp3[board[i][2]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> column_mp4;
        for (int i = 0; i < row; i++) {
            if (board[i][3] != '.') {
                column_mp4[board[i][3]]++;
                if (column_mp4[board[i][3]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> column_mp5;
        for (int i = 0; i < row; i++) {
            if (board[i][4] != '.') {
                column_mp5[board[i][4]]++;
                if (column_mp5[board[i][4]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> column_mp6;
        for (int i = 0; i < row; i++) {
            if (board[i][5] != '.') {
                column_mp6[board[i][5]]++;
                if (column_mp6[board[i][5]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> column_mp7;
        for (int i = 0; i < row; i++) {
            if (board[i][6] != '.') {
                column_mp7[board[i][6]]++;
                if (column_mp7[board[i][6]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> column_mp8;
        for (int i = 0; i < row; i++) {
            if (board[i][7] != '.') {
                column_mp8[board[i][7]]++;
                if (column_mp8[board[i][7]] > 1) {
                    return false;
                }
            }
        }
        unordered_map<char, int> column_mp9;
        for (int i = 0; i < row; i++) {
            if (board[i][8] != '.') {
                column_mp9[board[i][8]]++;
                if (column_mp9[board[i][8]] > 1) {
                    return false;
                }
            }
        }

        // scan sub-boxes
        unordered_map<char, int> mp0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (board[i][j] != '.') {
                    mp0[board[i][j]]++;
                    if (mp0[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        unordered_map<char, int> mp1;
        for (int i = 0; i < 3; i++) {
            for (int j = 3; j < 6; j++) {
                if (board[i][j] != '.') {
                    mp1[board[i][j]]++;
                    if (mp1[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        unordered_map<char, int> mp2;
        for (int i = 0; i < 3; i++) {
            for (int j = 6; j < 9; j++) {
                if (board[i][j] != '.') {
                    mp2[board[i][j]]++;
                    if (mp2[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        unordered_map<char, int> mp3;
        for (int i = 3; i < 6; i++) {
            for (int j = 0; j < 3; j++) {
                if (board[i][j] != '.') {
                    mp3[board[i][j]]++;
                    if (mp3[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        unordered_map<char, int> mp4;
        for (int i = 3; i < 6; i++) {
            for (int j = 3; j < 6; j++) {
                if (board[i][j] != '.') {
                    mp4[board[i][j]]++;
                    if (mp4[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        unordered_map<char, int> mp5;
        for (int i = 3; i < 6; i++) {
            for (int j = 6; j < 9; j++) {
                if (board[i][j] != '.') {
                    mp5[board[i][j]]++;
                    if (mp5[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        unordered_map<char, int> mp6;
        for (int i = 6; i < 9; i++) {
            for (int j = 0; j < 3; j++) {
                if (board[i][j] != '.') {
                    mp6[board[i][j]]++;
                    if (mp6[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        unordered_map<char, int> mp7;
        for (int i = 6; i < 9; i++) {
            for (int j = 3; j < 6; j++) {
                if (board[i][j] != '.') {
                    mp7[board[i][j]]++;
                    if (mp7[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        unordered_map<char, int> mp8;
        for (int i = 6; i < 9; i++) {
            for (int j = 6; j < 9; j++) {
                if (board[i][j] != '.') {
                    mp8[board[i][j]]++;
                    if (mp8[board[i][j]] > 1) {
                        return false;
                    }
                }
            }
        }

        return true;
    }
};
25500