Facebook phone screening questions
Company: Meta
Role: e3, e4
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
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 values 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 is not an average of its subtree, we should return true because we found one subtree satisfy the condition.