Source Code: https://thecodingsimplified.com/get-vertical-sum-of-binary-tree/
Solution:
- We'll take a map, where key will be vertical height,
- Vertical height of root will be 0
- As we're going left, vertical height will be decresed by 1 & if we're going right, it'll be increased by 1
- If map doesn't have that key height value, initialize a list & put value as 0 into it, if key already present, get the current value & add current node value
- At last, print complete map values, which'll print vertical sum for each vertical height
Time Complexity: O(n)
Space Complexity: O(n)
Do Watch video for more info
This Problem is synonym of following problems:
How to Get Vertical Sum of Binary Tree,
Binary tree Get Vertical Sum of Binary Tree,
Binary tree Get Vertical Sum of Binary Tree java,
Binary tree vertical sum,
Vertical Sum
vertical order,
Binary tree,
java,
Please check video for more info:
CHECK OUT CODING SIMPLIFIED
https://www.youtube.com/codingsimplified
★☆★ VIEW THE BLOG POST: ★☆★
http://thecodingsimplified.com
I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 200+ videos.
★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
https://www.youtube.com/codingsimplified?sub_confirmation=1
★☆★ Send us mail at: ★☆★
Email: [email protected]