java simple solution with explanation
\n int x; // number of x moves\n    int o; // number of o moves\n    \n    public boolean validTicTacToe(String[] board) {\n        if (!isValidMoves(board)) { 
```\n int x; // number of x moves\n    int o; // number of o moves\n    \n    public boolean validTicTacToe(String[] board) {\n        if (!isValidMoves(board)) { // check [(count(x)==count(y)) or (count(x)==count(y)+1)]\n            // because x always has first turn, so in order to be valid state these conditions needs to fulfilled\n            return false; \n        }\n        \n        boolean isXWinner = checkForWinner(board, \'X\'); // check if X is Winner\n        boolean isOWinner = checkForWinner(board, \'O\'); // check if O is Winner\n        \n        if (isXWinner && isOWinner) { // Both can\'t be winner\n            return false;\n        }\n        \n        if (isXWinner && x != o+1) { // x can win if count(x) == count(o)+1 \n            return false;\n        }\n        \n        if (isOWinner && x != o) { // o can win if count(x) == count(o)\n            return false;\n        }\n        return true;        \n    }\n    \n    private boolean checkForWinner(String[] board, char a) {\n        for (int i = 0; i < board.length; i++) { // check horizontal and vertical for win state\n            int count1 = 0;\n            int count2 = 0;\n            for (int j = 0; j < board[i].length(); j++) {\n                if (board[j].charAt(i) == a) {\n                    count1++;\n                }\n                if (board[i].charAt(j) == a) {\n                    count2++;\n                }\n            }\n            \n            if (count1 == 3 || count2 == 3) {\n                return true;\n            }\n            \n        }\n        \n        if ((board[0].charAt(0) == a &&\n           board[1].charAt(1) == a &&\n           board[2].charAt(2) == a)\n            ||\n            (board[0].charAt(2) == a &&\n           board[1].charAt(1) == a &&\n           board[2].charAt(0) == a)\n           ) { // check  diagonally for win state\n            return true;\n        }\n        return false; // else return false not possible for win\n    }\n    \n    private boolean isValidMoves(String[] board) {\n        for (String b : board) {\n            for (char a : b.toCharArray()) {\n                if (a == \'X\') {\n                    x++;\n                } else if (a == \'O\') {\n                    o++;\n                }\n            }\n        }\n        \n        return ((x==o) || (x == o + 1));\n    }\n```
['Java']