---
# System prepended metadata

title: Interview 2022/10/14

---

# Interview 2022/10/14

```python=

        4
    /        \
    8        5
  /    \      \
  0    1      6
## Count the number of nodes such that the average value of the
## subtree is equal to the value of the root node of the subtree.

# Include root value, number of nodes to divide also includes the root node
# Sum of the subtree
# Transverse the nodes, keep track of the totalvalue, count
# Average = totalvalue/count , check to see if the average == the root value
# If node->left == null and node->right == null, result+=1  
# Result += 1
# average(node->left)
# average(node->right)

4, [8, 5] total += 4

4, 8 [5, 0, 1] total+=8

4, 8 , 5, [0, 1, 6] total+=5

4, 8, 0, 1, 6 [] total+=(0+1+6)

            8
        4        3
    2       1 3        
    
if node == None:
    return 0, 0  
if(node.left == None and node.right == None):
    return node.val, 1

leftval, leftcount = (2+4+1), 3 # recursive function node->left
rightval, rightcount = (3+3+2), 3 # recursive function node->right

average = (leftval+rightval+root->val)/(leftcount+rightcount+1)

if average == root->val:
    result+=1

T(n) = 
    
    







