Boring ||Easy||beats 100% ,0ms || left, right, parent
Intuition\n Describe your first thoughts on how to solve this problem. \njust 3 ways\npick leftsubtree\npick rightsubtree\npick parent node\n# Approach\n Descri
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\njust 3 ways\npick leftsubtree\npick rightsubtree\npick parent node\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(H)\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n\n    int getsubtree(TreeNode* root, int &key, int &left, int &right, int &cur ){\n        if(root == NULL) return 0;\n\n        int lefty = getsubtree(root->left, key, left, right, cur);\n        int righty = getsubtree(root->right, key, left, right, cur);\n        if(root->val == key){\n            left = lefty;\n            right = righty;\n            cur = lefty + righty+1;\n        } \n\n\n        return lefty + righty+1;\n    }\n\n    //3 options pick any of two child or its parent\n    bool btreeGameWinningMove(TreeNode* root, int n, int x) {\n        int leftchild_subtree = -1;\n        int rightchild_subtree = -1;\n        int cursubtree = -1;\n\n        getsubtree(root, x, leftchild_subtree, rightchild_subtree, cursubtree);\n\n        if(leftchild_subtree > n-leftchild_subtree){\n            return true;\n        }\n        if(rightchild_subtree > n-rightchild_subtree){\n            return true;\n        }\n        if(n - cursubtree > cursubtree){\n            return true;\n        }\n\n        return false;\n\n    }\n};\n```
['Binary Tree', 'C++']