## 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));
}
}``````

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.

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.

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){
}
if(leftDepth>rightDepth)
{
return leftDepth;
}else
{
return rightDepth;
}
}

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

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

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

}``````

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

}

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

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

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

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.