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.
Maximum spiral sum = 4 + (-1) + (-2) + 1 + 5 = 7
Maximum Spiral Sum = 7
Time Complexity: O(n).
Auxiliary Space: O(n).
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.
- Clockwise Spiral Traversal of Binary Tree | Set - 2
- Clockwise Spiral Traversal of Binary Tree
- Anti Clockwise spiral traversal of a binary tree
- Reverse Clockwise spiral traversal of a binary tree
- Reverse Anti Clockwise Spiral Traversal of a Binary Tree
- Convert a Binary Tree into Doubly Linked List in spiral fashion
- Construct a Maximum Binary Tree from two given Binary Trees
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Maximum Path Sum in a Binary Tree
- Maximum XOR path of a Binary Tree
- Maximum width of a binary tree
- Find maximum (or minimum) in Binary Tree
- Find maximum among all right nodes in Binary Tree
- Find maximum level sum in Binary Tree
- Maximum sum of nodes in Binary tree such that no two are adjacent
- Sum of nodes at maximum depth of a Binary Tree | Set 2
- Find the maximum GCD of the siblings of a Binary Tree
- Sum of nodes at maximum depth of a Binary Tree
- Get maximum left node in binary tree
- Maximum parent children sum in Binary tree
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.