@all why you wants to change the tree structure do you know they don't
allow that otherwise it wont be amazon question
we can use Array as data Structure vertical sum in that as what jalaj
told
in case you wants to see working code check out \
http://shashank7s.blogspot.com/2011/02/wap-to-findo
My implementation tries to create a doubly linked list, each node of
which will hold the value of sum of all nodes in a particular
vertical.If there is no requirement for the final output to state
vertical number against the sum (and indeed there is no such
requirement in the question ), then my ap
hash would be a perfect choice.
I make a MinMaxHash class which would keep track of the min and max
value of the key.(since in this case we would never remove a key, thus
this primitive approach works. Otherwise use treeMap)
class MinMaxHash extends HashMap{
private Integer min = Integer.MAX_
Just a slight addition , you would also like to keep a record for the
maximum range of the levels (assuming the function is called as
(root , 0))
On Feb 14, 5:25 pm, jalaj jaiswal wrote:
> use hash
>
> take an array verticalsum[]={0};
>
> the function will be like this
> void vertcal_sum(node *r