Readable code with explanation | Beats 100%
\nclass Solution {\npublic:\n     bool didWon(int x,int y,vector<string>&m,char ch)\n   {\n    if(m[x][0]==ch&&m[x][1]==ch&&m[x][2]==ch)return true;\n    if(m[0
```\nclass Solution {\npublic:\n     bool didWon(int x,int y,vector<string>&m,char ch)\n   {\n    if(m[x][0]==ch&&m[x][1]==ch&&m[x][2]==ch)return true;\n    if(m[0][y]==ch&&m[1][y]==ch&&m[2][y]==ch)return true;\n    if(m[0][0]==ch&&m[1][1]==ch&&m[2][2]==ch)return true;\n    if(m[0][2]==ch&&m[1][1]==ch&&m[2][0]==ch)return true;\n       return false;\n   }\n    bool validTicTacToe(vector<string>& board) {\n        int numx = 0;\n        int numo = 0;\n\t\t//calculate number of the \'X\'s and \'O\'s\n        for(auto c: board)\n        {\n            for(auto a:c)\n            {\n                if(a==\'X\')numx++;\n                if(a==\'O\')numo++;\n            }\n        }\n\t\t//if number of \'O\'s greater than number of \'X\'s that means B took more moves which is unacceptable, so return false;\n        if(numo>numx)return false;\n\t\t//If number of \'X\'s greater than number of \'O\'s by 1 that means at one point 2nd player didn\'t get his turn So return false\n        if(numx-numo>1)return false;\n\t\t//if there are equal number of \'X\'s and \'O\'s then, if 1st player is winner then 2nd player shouldn\'t get any chance So return false if 1st player is Winner.\n        if(numx==numo)\n        {\n           bool flag1 = true;\n           bool flag2 = true;\n             for(int i=0;i<3;i++){\n                for(int j=0;j<3;j++) {\n                    if(board[i][j]==\'X\') {\n                        if(didWon(i,j,board,\'X\')){\n                            flag1=false;\n                            break;\n                        } \n                    }\n                }\n            }\n            if(!flag1)return false;\n        }\n\t\t//if difference between  moves of 1st player and 2nd player is equal to one.. Again if 2nd player is  winner then 1st player shouldn\'t get extrachance. But here 1st player got one extra chance so return false\n        if(numx-numo==1)\n        {\n            for(int i=0;i<3;i++)\n            {\n                for(int j=0;j<3;j++)\n                {\n                    if(board[i][j]==\'O\')\n                    {\n                        if(didWon(i,j,board,\'O\'))return false;\n                    }\n                }\n            }      \n        }\n\t\t//else return true if none of the above conditions failed to prove the state as invalid. \n        return true;\n    }\n};\n\n//Please upvote if you liked it. \n//Thanks\n```
['C', 'C++']