Maximum spiral sum in Binary Tree
Given a binary tree containing n nodes. The problem is to find the maximum sum obtained when the tree is spirally traversed. In spiral traversal one by one all levels are being traversed with the root level traversed from right to left, then next level from left to right, then further next level from right to left and so on.
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.
Maximum spiral sum = 4 + (-1) + (-2) + 1 + 5 = 7
Maximum Spiral Sum = 7
Time Complexity: O(n).
Auxiliary Space: O(n).