Sum Of Nodes On The Longest Path From Root To Leaf Node

preview_player
Показать описание
JOIN ME
—————

COMPLETE PLAYLIST
————————————

INTERVIEW PLAYLIST
————————————

QUICK SHORT VIDEOS
————————————-

In this video we will learn how to find sum of nodes on the longest path from root to leaf node, and if there is not single path then we will choose the maximum sum b/w competing paths.
I have used recursion way to solve the problem. This question is expected in computer science and electronics background interview questions.

#pathsum #tree #graph #dfs #dsalgo #datastructures #algorithms
Рекомендации по теме
Комментарии
Автор

very easy, very simple and straight to the point explanation

vinayakupadhyay
Автор

i've implemented the solution for this question in Java, it might not be the best..

public static int height(BinNode<Integer> tree)
{
if(tree == null)
return -1;

return 1 + Math.max(height(tree.getLeft()), height(tree.getRight()));
}

public static int tree)
{
int height = height(tree);
return actual_func(tree, height);
}

public static int actual_func(BinNode<Integer> tree, int height)
{
if(tree == null)
return 0;

if(height == 0)
return tree.getValue();

return tree.getValue() + Math.max(actual_func(tree.getLeft(), height - 1), actual_func(tree.getRight(), height - 1));
}

denissobolevski
Автор

Hi Rupesh, do you have an idea how to read a stream of (key-value pairs) JSON input using c++ and do dictionary encoding to the input and converting the output to a Binary file?

zadinho
Автор

Thanks a lot for such an infomrative video. Which drawing tool are you using to draw on screen??

ChandraShekhar-bycd
Автор

Hello rupesh
Waiting for semaphore in threading cpp

amarnathgandhi
Автор

nitpicking: The code wont compile because there needs to be some return value from the function at the end isnt it?

subenduu