## Bloomberg LP Interview Question for Financial Application Engineers

• 2

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
0
of 0 vote

void sumValue(Node *n, list<int> iValueList, int value)
{
if( n == 0 )
{
return;
}
value += n->value;
if( n->left == 0 && n->right == 0 )
{
printf("leaf node v:%d\n", value);
iValueList.push_front(value);
}
sumValue(n->left, iValueList, value);
sumValue(n->right, iValueList, value);
}

bool findLeafMaxValueSum(int& out)
{
list<int> list;
int value = 0;
sumValue( root, list ,value);
out = 0;
if( list.size() > 0 )
{
list<int>::iterator itr;
for( itr = list.began(); itr != list.end(); itr++ )
{
if( *itr > out )
{
out = *itr;
}
}
return true;
}else{
return false;
}
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int find_Max(Node *root){
int sum=0;
if (root==null)
return 0;
else
{
int left_sum=find_Max(root->left);
int right_sum=find_Max(root->right);
sum=max( left_sum,right_sum)+root->value;
return sum;
}
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int findMaxSum(TreeNode node)
{

if(node == null)
return 0;

else
{
sum_left = node.value + findMaxSum(node.leftchild);
sum_right =node.value+ findMaxSum(node.rightchild);
return Math.max(sum_left,sum_right);

}

}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

Do we have to calculate the sum of values from root to each leaf and then identify the path with maximum value? If so, Googler's solution seems to be in line, but seems to be working differently by the solution from yogi.rulzz. Or am I missing something here :(

Comment hidden because of low score. Click to expand.
0

I think my answer is not good to this question. However, if we need to sort sum values for each leafs, mine is one option.

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public static int findMaxSum(Node n){
if(n == null){
return 0;
}
int maxSumChildren = Math.max(findMaxSum(n.left), findMaxSum(n.right));
return n.data + maxSumChildren;
}``````

Comment hidden because of low score. Click to expand.
-1
of 1 vote

Notice Jielei's answer right there in the initial post.

``int doit(Node x){ if(x) return max((doit(x.left), doit(x.right)) + x.val; return 0; }``

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.