We can do this in $\theta(n^2)$ time if we calculate the average of all couples of nodes in the tree and compare it to the root, but this is too much time.
We can do this in linear time but with extra space by saving the in-order traversal of the left sub tree to array A, and the right sub tree to array B.
Now for the first node in A, scan B, until we find the matching node in B, or until we reach a too large element in B save that index as $k$.
If it is the second case, iterate over the rest of A and for each node:
Traverse B backwards from index $k-1$ until we find the matching node, or, if we reached a node that is too small, save the index as $k-2$ and repeat.
This takes $\theta(n)$ time but is using extra space. How can we do this in $\theta(n)$ and without extra space?