Facebook phone screening questions
Anonymous User
1094

1- Given a binary tree, check if the parent's value is equal to the sum of its subtree (not only the sum of the left and right children but the whole subtree, negative vlues allowed).
2- A follow up question, Given a binary tree, check if the parent's value is equal to the average of its subtree (not only the sum of the left and right children but the whole subtree, negative values allowed).

         5
       /  \
       3  2
      / \
     4  3
    /
   2

True: 3 is the average of (4+3+2)/3

Return true if any subtree satisfy that condition ex: True: 3 is the average of (4+3+2)/3 even though 5 in not an average of its subtree, we should return true because we found one subtree satisfy the condition.

Comments (7)