3
bool win(vector<string> board, char player, int size) {4
int row_win = 0, col_win = 0, diagonal_win = 0, rev_diagonal_win = 0;6
for (int i = 0; i < 3; i++) {10
for (int j = 0; j < 3; j++) {11
if (player == board[i][j]) {13
if (row_win == 3) return 1;16
if (player == board[j][i]) {18
if (col_win == 3) return 1;21
if (i == j && player == board[i][j]) {25
if (i + j == size - 1 && player == board[i][j]) {31
if (diagonal_win == 3 || rev_diagonal_win == 3) return 1;36
bool validTicTacToe(vector<string> &board) {37
int count_x = 0, count_o = 0, size = board.size();38
for (auto i : board) {46
if (count_o > count_x || count_x - count_o >= 2) return false;47
if (count_x >= 3 && count_x == count_o && win(board, 'X', size)) return false;48
if (count_o >= 3 && count_x > count_o && win(board, 'O', size)) return false;