Java Solution with explanation
My approach is a bit lengthy.\nI broke down the problem into 2 subcases.\n\nCASE 1\nWe calcaulate the number of nodes in the subtree rooted at X, and if the num
My approach is a bit lengthy.\nI broke down the problem into 2 subcases.\n\n**CASE 1**\nWe calcaulate the number of nodes in the subtree rooted at `X`, and if the number of nodes in in this subtree is greater then the count of rest of the nodes in the tree we return false.\n\n**CASE 2**\nIn this approach, we calcaculate the number of nodes in the left and right sub tree of the tree rooted at `X`, now comes the tricky part, we would choose the `maximumOf(leftSubtreeCount, rightSubtreeCount)` as `Y`. Now since `Y` is one  of the child of `X`, so the nodes above `X` would be coloured by `X`. In short,\n```\nCount of X = mininmumOf(leftSubtreeCount, rightSubtreeCount) + rest of the nodes in tree\nCounf of Y = maximumOf(leftSubtreeCount, rightSubtreeCount)\n\nif(Count of X < Count of Y){\n\treturn true;\n}\n```\nIn the end with return the `OR` of the cases.\n\n**CODE**\n```\nclass Solution {      \n    public boolean btreeGameWinningMove(TreeNode root, int n, int x) {\n                \n        // Case 1\n        TreeNode nodex = findX(root, x);\n        int countofx = countNodes(nodex);\n        int countofy = n - countofx;\n        boolean case1 = countofy>countofx;\n        \n        //Case 2\n        boolean case2 = helper(root,x,n,0);\n\n        return case1 || case2; \n    }\n    \n    \n    public static boolean helper(TreeNode root, int x, int n, int count){\n        if(root==null){\n            return false;\n        }      \n        if(root.val == x){\n            int leftsubtree = countNodes(root.left);\n            int rightsubtree = countNodes(root.right);\n            \n            int temp = Math.min(rightsubtree,leftsubtree) + n-(rightsubtree+leftsubtree+1);\n            return temp < Math.max(leftsubtree,rightsubtree);\n        }        \n        boolean l = helper(root.left, x, n, count+1);\n        boolean r = helper(root.right, x, n, count+1);\n        return l||r;\n    }\n    \n    //Method to find the node with value X\n    public static TreeNode findX(TreeNode root, int x){\n        if(root==null){\n            return null;\n        }        \n        if(root.val == x){\n            return root;\n        }\n        TreeNode lft = findX(root.left,x);\n        if(lft!=null){\n            return lft;\n        }\n        return findX(root.right,x);\n    }\n    \n    \n    //Method to count number of nodes\n    public static int countNodes(TreeNode root){\n        if(root==null){\n            return 0;\n        }\n        return 1+ countNodes(root.left)+countNodes(root.right);\n    }   \n}\n```
[]