Simple C++ Using Basic Recursive Functions
\t\t\t\t\t\t\t\t#Vote if u like\u2764\uFE0F\n\t\tTo_Do:\n\t\t\t1.For this question we need to have sum , no.of nodes in subtree than need to find the average \n
\t\t\t\t\t\t\t\t#Vote if u like\u2764\uFE0F\n\t\tTo_Do:\n\t\t\t1.For this question we need to have sum , no.of nodes in subtree than need to find the average \n\t\t\t2.Than we need to check the value of the root and the average if same increment the count\n\t\t\t\n\t\tProcess:\n\t\t\t1. Need to create a function by which we can get the sum of the nodes under it \n\t\t\t2. Need to create a function so we can get the count of nodes \n\t\t\t3. Than need to traverse the tree and find the average by using the above funtions\n\t\t\t\n\t     Code:\t\n\t\t \n\t\t\tclass Solution {\n\t\t\tpublic:\n\t\t\t\tint SumofNode(TreeNode *root) //Funtion to get Sum\n\t\t\t\t{\n\t\t\t\t\tif(root == NULL) return 0; //Tree empty return 0;\n\t\t\t\t\tint left = SumofNode(root -> left); //Left subtree will give ans to parent\n\t\t\t\t\tint right = SumofNode(root -> right); // Right subtree will give ans to parent\n\t\t\t\t\treturn left + right + root -> val; //We need to add root val also\n\t\t\t\t}\n\t\t\t\tint CountofNode(TreeNode *root)\n\t\t\t\t{\n\t\t\t\t\tif(root == NULL) return 0; //Tree empty return 0;\n\t\t\t\t\tint left = CountofNode(root -> left);//Left subtree will give ans to parent\n\t\t\t\t\tint right = CountofNode(root -> right);// Right subtree will give ans to parent\n\t\t\t\t\treturn left + right + 1;//We need to count  root also\n\t\t\t\t}\n\t\t\t\tvoid fun(TreeNode *root , vector<pair<int , int>>&m)\n\t\t\t\t{\n\t\t\t\t\tif(root == NULL) return; //Tree empty return \n\t\t\t\t\tint x = SumofNode(root); //Sum of root\n\t\t\t\t\tint y = CountofNode(root); //no.of roots\n\t\t\t\t\tm.push_back({root -> val , (x * 1.0 / y)}); //Storing in vector\n\t\t\t\t\tfun(root -> left , m); //Passing the left root\n\t\t\t\t\tfun(root -> right , m);//PAssing the right root\n\t\t\t\t}\n\t\t\t\tint averageOfSubtree(TreeNode* root) {\n\t\t\t\t\tif(root == NULL) return 0; //Tree empty return 0;\n\t\t\t\t\tint count = 0;\n\t\t\t\t\tvector<pair<int , int>> m; //list to store the values\n\t\t\t\t\tfun(root , m);//Calling the function to get the values to vector\n\t\t\t\t\tfor(auto p: m)// Checking the root val and avg val if same increment count\n\t\t\t\t\t\tif(p.first == p.second) count++;\n\t\t\t\t\treturn count;//Return count\n\t\t\t\t}\n\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-Yash:)\n\t\t\t\n\t\t\t
['Recursion', 'C', 'C++']