[C++] Clean and concise solution [Detailed Explanation]
\n/*\n    https://leetcode.com/problems/valid-tic-tac-toe-state/\n    \n    TC: O(N*N)\n    \n    Idea is simple, since X starts first, no. of X should either b
```\n/*\n    https://leetcode.com/problems/valid-tic-tac-toe-state/\n    \n    TC: O(N*N)\n    \n    Idea is simple, since X starts first, no. of X should either be equal or +1 than no. of O.\n    We check for this scenario and few others. If a strike (continuous 3X or 3O) is completed, then\n    based on which symbol completed, the no. of X and O is different.\n    Check the state of Xs and Os after these scenarios:\n    1. Horizontal Strike\n    2. Vertical Strike \n    3. Right Diagonal\n    4. Left Diagonal\n*/\nclass Solution {\npublic:\n    // Checks if the strike is valid or not based on the no. of Xs and Os.\n    // Returns true if the continuous line of 0s or Xs is valid based on the config of board\n    bool validStrike(int nX, int nO, int n, int total_x, int total_o) {\n        if(nX == n or nO == n) {\n            // Since X makes the 1st move, if it completes a strike, nO should always be 1 less\n            if(nX == n && (total_o >= total_x))\n                return false;\n            // Since O makes the 2nd move, if it completes a strike, it should be equal to X\n            if(nO == n && (total_o != total_x))\n                return false;\n        }\n        return true;\n    }\n    \n    bool validTicTacToe(vector<string>& board) {\n        // n(x) == n(O) or x(X) == n(O) + 1\n        // no moves after straight 3 Os or Xs => 3X (nX = nO + 1), 3O (nX = nO) \n        int total_x = 0, total_o = 0;\n        int n = board.size();\n        // <char=[X, O], no. of chars>\n        // Used just to make the code cleaner\n        unordered_map<char, int> freq;\n        \n        // calculate total X and O\n        for(int r = 0; r < n; r++)\n            for(int c = 0; c < n; c++)\n                ++freq[board[r][c]];\n        \n        total_x = freq[\'X\'], total_o = freq[\'O\'];\n        // Since X starts first, no. of X should either be equal or +1 than no. of O\n        if(total_x != total_o + 1 && total_x != total_o)\n            return false; \n        \n        // check for 3 Xs or Os: Horizontally \n        for(int r = 0; r < n; r++) {\n            freq.clear();\n            for(int c = 0; c < n; c++)\n                ++freq[board[r][c]];\n            // Found a horizontal strike\n            if(!validStrike(freq[\'X\'], freq[\'O\'], n, total_x, total_o))\n                return false;\n        }\n        \n        // check for 3 Xs or Os: Vertically \n        for(int c = 0; c < n; c++) {\n            freq.clear();\n            for(int r = 0; r < n; r++)\n                ++freq[board[r][c]];\n            // Found a vertical strike\n            if(!validStrike(freq[\'X\'], freq[\'O\'], n, total_x, total_o))\n                return false;\n        }\n        \n        freq.clear();\n        // check for a diagonal strike: Right upwards diagonal\n        int r = 0, c = n-1;\n        while(r < n && c >= 0) {\n            ++freq[board[r][c]];\n            ++r, --c;\n        }\n        // Found a diagonal strike\n        if(!validStrike(freq[\'X\'], freq[\'O\'], n, total_x, total_o))\n            return false;\n\n        freq.clear();\n        // check for a diagonal strike: Left downwards diagonal\n        r = 0, c = 0;\n        while(r < n && c < n) {\n            ++freq[board[r][c]];   \n            ++r, ++c;\n        }\n        // Found a diagonal strike\n        if(!validStrike(freq[\'X\'], freq[\'O\'], n, total_x, total_o))\n            return false;\n        return true;\n    }\n};\n```
['C', 'C++']