Total sum except adjacent of a given node in a Binary Tree
Given a BT and a key Node, find the total sum in BT, except those nodes which are adjacent to key Node.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
1. Traverse the tree using pre-order.
2. If the current node is adjacent to the key then do not add it to the final sum.
3. If the current node is the key then do not add its children to the final sum.
4. If the key is not present then return the sum of all nodes.
Time Complexity: O(n) where n is a number of nodes in BT.