Bloomberg LP Interview Question for Financial Software Developers


Country: United States
Interview Type: Phone Interview




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

int findMaxDepth(Node root){
		if(root==null)
			return 0;
		else{
			return 1+Math.max(findMaxDepth(root.left),findMaxDepth(root.right));
		}
	}

- sharath February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Given a tree with a single root node, this function returns depth 1. When by definition, the depth in this case should be 0.

- xdoer February 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Nope. By definition, an empty tree (null) has depth 0. So, a tree with a single node has depth 1.

- tolga March 01, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

/* depth should be ZERO for the first call*/
int Maxdepth(root, depth){
if(root==NULL){
return depth;
}
if(root!=NULL){
leftDepth=Maxdepth(root->Leftlink, depth+1);
rightDepth=MaxDepth(root->Rightlink,depth+1)
}
if(leftDepth>rightDepth)
{
return leftDepth;
}else
{
return rightDepth;
}
}

- Samantra February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

recursivedepth(valueh,root)
{
valueh++;
if(valueh >height)
{
height=valueh;
}
if(root.lchild !=null)
{
recursivedepth(valueh,root.lchild);
}
if(root.rchild !=null)
{
recursivedepth(valueh,root.rchild);
}
}



I donno whether this is the optimal solution for this problem are can come up with some other

- sai s February 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

GetMaxDepth(root)
{
if(root is null)
return 0;

return Maximum( GetMaxDepth(root->left) , GetMaxDepth(root->right) ) + 1;
}

- Sudhindra.A February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int Tree::height(node *p)
{
 if( (root == NULL) || (p == NULL) )
         return 0;
         
  if(p != NULL)
  {
   lh = height(p->left);
   rh = height(p->right);     
  }
  if(lh >= rh)
        return (lh+1);
  else
        return (rh+1);
        
           
}

- krishnx February 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int maxDepth(TreeNode* node)
{
    if(node == nullptr)
        return 0;

    return max(maxDepth(node->leftChild), maxDepth(node->rightChild)) + 1;

}

- Gabe April 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

static int maxDepth = 0;
public static void getMaxDepth(Node node, int curDepth) {
	if(node == null) return;
	curDepth++;
	if(maxDepth<curDepth) maxDepth++;
	getMaxDepth(node.getLeft(), curDepth);
	getMaxDepth(node.getRight(), curDepth);	
}

- Sumit Kapoor February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

static int maxDepth; // <---- YUCK.

- Anonymous February 08, 2013 | Flag


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