c++ can be scaled to any size
\nclass Solution {\npublic:\n    bool validTicTacToe(vector<string>& board) {\n        const int N = 3;\n\n        unordered_map<char, int> total;\n        unor
```\nclass Solution {\npublic:\n    bool validTicTacToe(vector<string>& board) {\n        const int N = 3;\n\n        unordered_map<char, int> total;\n        unordered_map<char,int> winner;\n        \n        vector<unordered_map<char, int>> rows(N);\n        vector<unordered_map<char, int>> cols(N);\n        \n        unordered_map<char, int> diag;\n        unordered_map<char, int> rdiag;\n                \n        for (int i=0; i<N; i++)\n            for (int j=0; j<N; j++) {\n                int c = board[i][j];\n                \n                total[c]++;\n\n                if (i == j)\n                    if (++diag[c] == 3)\n                        winner[c]++;\n                        \n                if (i == N-j-1)\n                    if (++rdiag[c] == 3)\n                        winner[c]++;\n                \n                if (++rows[i][c] == 3)\n                    winner[c]++;\n                if (++cols[j][c] == 3)\n                    winner[c]++;\n            }\n        \n        int XO = total[\'X\']-total[\'O\'];\n\n        if (XO < 0 || XO > 1)\n            return false;\n        \n        if (winner[\'X\'] > 0 && winner[\'O\'] > 0)\n            return false;\n        \n        if (winner[\'X\'] > 0  && XO == 0)\n            return false;\n\n        if (winner[\'O\'] > 0  && XO > 0)\n            return false;\n        \n        return true;\n    }\n};\n```
[]