C++ Easy To Understand Code with Explanation
Given that total nodes are n.\n###### For any node x, \n###### a.find the count of nodes in the left subtree \n###### b.and the count of nodes in the right subt
###### Given that total nodes are n.*\n###### For any node x, \n###### a.find the count of nodes in the left subtree \n###### b.and the count of nodes in the right subtree\n###### c.Count of nodes above node x(remaining tree) will be n-(a)-(b)-1\n###### If player 2 picks the right child, the right subtree is blocked for player 1\n###### If he picks the left child, the left subtree is blocked.Similary on picking the parent node, the remaining nodes are blocked\n###### Condition for player 2 to win:\n######  a>b+c or b>a+c or c>a+b*\n\n   class Solution {\n   public:\n\n    int count(TreeNode* root)\n    {\n        if(root==NULL) return 0;\n        \n        return 1+count(root->left)+count(root->right);\n    }\n    \n    TreeNode* find(TreeNode*root,int x)\n    {\n        if(root==NULL)\n            return NULL;\n        if(root->val==x)\n            return root;\n        \n        TreeNode* l=find(root->left,x);\n        TreeNode* r=find(root->right,x);\n        if(l==NULL) return r;\n        return l;\n    }\n    bool btreeGameWinningMove(TreeNode* root, int n, int x) {\n       TreeNode* xpos=find(root,x);\n       int a=count(xpos->left);\n       int b=count(xpos->right);\n       int c=n-a-b-1;\n       if(a>b+c) return true;\n       if(b>a+c) return true;\n       if(c>a+b) return true;\n       return false;\n    }\n    };
[]