Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines. 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 So expected output is 4, 2, 12, 3 and 7
23 times
ReplyDelete@Dave 22 times a day if you only count the minute and hour hands overlapping.
ReplyDeleteif you have any explanation for your answer please do comment.
should be 24 times of the minute n hour hands !
ReplyDelete@anonymous can you please explain..
ReplyDeleteIf you start from 1 to 12 hours a day it overlaps 12 times and similarly for another 12 hours which makes it 24
ReplyDelete@ Overlapping will occur when Lm = Lh +N, which means every N*(12/11) hours (for N = 0,1,2,3...). In other words, it will happen approximately every 1hr5mins27secs, starting at 00:00. In 24hours, this occurs a total of 24/(12/11) = 22..
ReplyDeletedo give your explanations..
The hour and the minutes clock coincide every 1 hr 5 min as u said but i think it happens 24 times as shown below:
ReplyDeleteOO:00, 01:05, 02:10, 03:15, 04:20, 05:25, 06:30, 07:35, 08:40, 09:45, 10:50, 11:55, 12:00, 13:05, 14:10, 15:15, 16:20, 17:25, 18:30, 19:35, 20:40, 21:45, 22:50, 23:55..this adds up to 24 times..will you please explain which cases your algorithm leaves from above.
@above here are overlapping times :
ReplyDeleteam
12:00
1:05
2:11
3:16
4:22
5:27
6:33
7:38
8:44
9:49
10:55
pm
12:00
1:05
2:11
3:16
4:22
5:27
6:33
7:38
8:44
9:49
10:55