C++ || DFS || with Explanation
\nclass Solution {\npublic:\n       \n        pair<int,int> path(TreeNode* root)\n\t\t//this function is used to calculate the sum of subtree and the number of 
```\nclass Solution {\npublic:\n       \n        pair<int,int> path(TreeNode* root)\n\t\t//this function is used to calculate the sum of subtree and the number of nodes in subtree\n        {\n            if(!root)return {0,0};\n            pair<int,int> lh=path(root->left);\n            pair<int,int> rh=path(root->right);\n            return {root->val+lh.first+rh.first,1+lh.second+rh.second};\n            //root->val+lh.first+rh.first --->sum of subtree\n            //1+lh.second+rh.second---->number of nodes;\n        }\n    \n        void inorder(TreeNode* root,int &cnt){\n            if(!root)return;\n            pair<int,int> x=path(root);//pair of sum and count of nodes\n            if(root->val==(x.first/x.second))//(x.first/x.second)-->calculating avg\n            {cnt++;}//if avg==root->val then increment the count\n            inorder(root->left,cnt);\n            inorder(root->right,cnt);\n            return;\n            \n        }\n    \n        int averageOfSubtree(TreeNode* root) {\n        if(!root)return 0;\n        int cnt=0;\n        inorder(root,cnt);\n            return cnt;\n    }\n};\n```
['Tree', 'Depth-First Search', 'Recursion', 'Binary Tree']