Recursion|DS
\n/**\n * @param {string[]} board\n * @return {boolean}\n */\nvar validTicTacToe = function(board) {\n    const chance = new Array(3).fill(\'\').map(a => new Ar
```\n/**\n * @param {string[]} board\n * @return {boolean}\n */\nvar validTicTacToe = function(board) {\n    const chance = new Array(3).fill(\'\').map(a => new Array(3).fill(\' \'));\n    let x = 0;\n    let y = 0;\n    let xWinner = findWinner(\'X\', board);\n    let yWinner = findWinner(\'O\', board);\n    if (xWinner && yWinner) return false;\n    function findWinner(check, board2) {\n        let win = 0;\n       for (let i = 0; i < board2.length; i +=1 ) {\n            if (board2[i][0] === check && board2[i][1] === board2[i][0] && board2[i][1] === board2[i][2]) win++;\n       }\n        for (let j = 0; j < board2.length; j +=1 ) {\n            if (board2[0][j] === check && board2[1][j] === board2[0][j] && board2[1][j] === board2[2][j]) win++;\n       }\n        if (board2[0][0] === check && board2[1][1] === board2[0][0] && board2[1][1] === board[2][2]) win++;\n        if (board2[2][0] === check && board2[1][1] === board2[2][0] && board2[1][1] === board2[0][2]) win++;\n        return win;\n    }\n    for (let i = 0; i < board.length; i +=1 ) {\n        for (let j = 0; j < board[i].length; j += 1) {\n            if (board[i][j] === \'X\') x++;\n            if (board[i][j] === \'O\') y++;\n            \n        }\n    }\n    if ((x - y) > 1 || (x - y) < 0) return false;\n    return Xcheck(chance, 0, 0);\n    function validate(chance) {\n        for (let i = 0; i < 3; i += 1 ) {\n            if (chance[i].join(\'\') !== board[i]) return false;\n            \n        }\n        return true;\n    }\n    function Xcheck(chance, X, Y) {\n\n        if (X > x || Y > y) return false;\n                // console.log(chance);\n        if (X === x && Y === y) {\n            // console.log(chance);\n           if (validate(chance)) {\n                return true;\n            } else {\n                return false;\n            }\n        }\n        if (X >= 3) {\n\t\t// check if the player can win\n            if (findWinner(\'X\', chance)) return false;\n        }\n        if (Y >= 3) {\n            // check if the player can win\n           if (findWinner(\'O\', chance)) return false;\n        }\n        \n        for (let i = 0; i < 3; i += 1) {\n            for (let j = 0; j < 3; j += 1) {\n                if (chance[i][j] === \' \') {\n                    if ( X === Y && board[i][j] === \'X\') {\n\t\t\t\t\t// add X only where board [i][j] has it & find if X is clever enough to win or not\n                        chance[i][j] = \'X\';\n                        if (Xcheck(chance, X + 1, Y)) return true;\n                    } else if (X > Y && board[i][j] === \'O\') {\n\t\t\t\t\t// add O only where board [i][j] has it & find if O is clever enough to win or not\n                       chance[i][j] = \'O\';\n                       if (Xcheck(chance, X, Y + 1)) return true;\n                    }\n                    chance[i][j] = \' \';\n                }\n            }\n         }\n        return false;\n    }\n};\n```
[]