Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Vertical Sum of a Binary Tree. (Column-Wise Sum)

$
0
0

Hello everybody, I was solving a Data-Structure Problem , Finding the Vertical Sum in a binary tree.
Vertical Sum means sum of nodes in same column.
Let me explore the question with an example.

Examples:

      1
    /   \
  2      3
 / \    / \
4   5  6   7

The tree has 5 vertical lines

Vertical-Line-1 has only one node 4 => vertical sum is 4
Vertical-Line-2: has only one node 2=> vertical sum is 2
Vertical-Line-3: has three nodes: 1,5,6 => vertical sum is 1+5+6 = 12
Vertical-Line-4: has only one node 3 => vertical sum is 3
Vertical-Line-5: has only one node 7 => vertical sum is 7

We can find this problem here link also on @geeksforgeeks.

I got the concept of Horizontal Distance.

My problem is how to implement Hash Map in C++ ??
In that we have keys with -ve values.

Please any-body explain how to implement Hash-Map in C++ .

Thanks and Happy Coding!!!


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>