Block Corona | C++ | Easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \nBlock Corona\n\n# Approach\n Describe your approach to solving the problem. \nUnderstan
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBlock Corona\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUnderstand it like red is corona and it can spread in 3 direction(upper, leftBottom, rightBottom) and you can block it\'s any one direction and you have to minimize the spread so minimum people die which side you will block?\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\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    int countNode(TreeNode *root, TreeNode *obstacle){\n        if(root == NULL || root == obstacle) return 0;\n        int l = countNode(root->left, obstacle);\n        int r = countNode(root->right, obstacle);\n        return l + r + 1;\n    }\n    TreeNode *findXNode(TreeNode *root, int x){\n        if(root == NULL) return NULL;\n        if(root->val == x) return root;\n        TreeNode *l = findXNode(root->left,x);\n        TreeNode *r = findXNode(root->right,x);\n        if(l != NULL) return l;\n        if(r != NULL) return r;\n        return NULL;\n    }\n    bool btreeGameWinningMove(TreeNode* root, int n, int x) {\n        TreeNode *xNode = findXNode(root, x);\n        int p1 = countNode(xNode->left, NULL);\n        int p2 = countNode(xNode->right, NULL);\n        int p3 = countNode(root,xNode);\n        if(p1 > p2 && p1 > p3){ // i am assuming i will block p1 dir\n            return p1 > p2 + p3;\n        }\n        if(p2 > p1 && p2 > p3){ i am assuming i will block p2 dir\n            return p2 > p1 + p3;\n        }\n        if(p3 > p1 && p3 > p2){ i am assuming i will block p3 dir\n            return p3 > p1 + p2;\n        }\n        return false;\n    }\n};\n```
['C++']