how can we print the nodes on maximum sum path elements??
Maximum sum path in a binary tree?
@shampblocks hey ,jab bhi ap node pr traverse krrhe ho to ek vector me node ki value push krate jao and jab hmara current sum compare horha ho tab agr hmara sum bda hai to hmare answer vector ko isse replace ya copy krdo.Hope you get it.
This is not my doubt sir i want to ask how to get the elements of that path which contains maximum sum?? As the maximum sum we can calculate easily but how to print those elements??
@shampblocks bhai wahi bta rha hoon,ki ap jab tree ko traverse krrhe ho to nodes ko vector me store krao while traversing and jha ap current sum ko compare krrhe res agr current sum bda hai to us vector ko print kra do ya ans vector me store kra do.
But sir maxum. Sum. Is changing in every node it might be possible that if a sum. Is maximum. At particular stage it might not include in the whole tree sum. Because sum is coming from. Right and left subtree??
Bhaiya can you clear??
@shampblocks hi bro,ye wale question me actually hm print nhi kra skte ,if sum condition is given like k sum or root to leaf path ,then mera wala logic chl jata ,tumne jo likha upr sahi hai,mene questiom contemt galat dekh lia tha ,sorry ,is question me ap sirf max sum nikal skte ho.
so sir we cannot print that path ?? or is there some way??
@shampblocks bhai hm us path ko print nhi kr skte is question me ,print wale question me specific dia hua hota hai ki root to leaf path chyy unhe.
ya i know in this quesion hume print nhi krn but if i want to print how can i approach i want hint??
@shampblocks bhai as such koi way nhi hai ap ek vector lelo aur traverse krte hue usme node value push krdo, har jgah jha sum compare krrhe ho agr woh sum prev se bda hai to apne ans vector ko current vector se replace krdo ,bs yhi way hai.
ohk bhaiya thanks…