Only One Iteration on Board C++, only 3ms  - can be easily scaled for any size board
\nclass Solution {\n\tpublic:\n\n\t// solved using only one iteration over board\n    bool validTicTacToe(vector& board) {\n        bool wony = false, wonx = fa
\nclass Solution {\n\tpublic:\n\n\t// solved using only one iteration over board\n    bool validTicTacToe(vector<string>& board) {\n        bool wony = false, wonx = false;\n        int rows = board.size();\n        int cols = rows ? board[0].size() : 0;\n        int diax = 0, diay = 0, xdiax = 0, xdiay = 0, x_count = 0, y_count = 0;\n        \n        for(int i = 0; i < rows; i++) {\n            int rowsx = 0, rowsy = 0;\n            int colsx = 0, colsy = 0;\n            for(int j = 0; j < cols; j++) {\n                // see current row\n                if(board[i][j] == \'X\')\n                    rowsx++,x_count++;\n                if(board[i][j] == \'O\')\n                    rowsy++, y_count++;\n                // see ith column\n                if(board[j][i] == \'X\')\n                    colsx++;\n                if (board[j][i] == \'O\')\n                    colsy++;\n            }\n            \n            // see both the diagonals\n            if(board[i][i] == \'X\')\n                diax++;\n            if(board[i][i] == \'O\')\n                diay++;\n            if(board[i][cols - 1 - i] == \'X\')\n                xdiax++;\n            if(board[i][cols - 1 - i] == \'O\')\n                xdiay++;\n            \n            if(rowsx == 3 || colsx == 3 || diax == 3 || xdiax == 3)\n                wonx = true;\n            \n             if(rowsy == 3 || colsy == 3 || diay == 3 || xdiay == 3)\n                wony = true;\n        }\n        \n        if(!(x_count == y_count || x_count == y_count + 1))\n            return false;\n        \n        if((wonx && wony) || (wonx && x_count == y_count) || (wony && x_count != y_count))\n            return false;\n        \n        return true;\n    }\n};
[]