Bloomberg LP Interview Question for Financial Application Engineers


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;
}
}

- Googler October 26, 2013 | Flag Reply
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;
   }
}

- yogi.rulzz October 26, 2013 | Flag Reply
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);
        	
        }
            
    
    }

- RS October 26, 2013 | Flag Reply
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 :(

- ruharish October 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- Googler October 27, 2013 | Flag
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;
	}

- A Non November 05, 2013 | Flag Reply
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; }

- Urik's twin Cookie Monster (dead now) October 29, 2013 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More