Adobe Interview Question for Computer Scientists






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

/* height of Binary tree recursively */
	private static Integer heightRecursively(BinaryTreeNode root) {
		int leftHeight, rightHeight;
		if (root == null)
			return 0;
		else {
			leftHeight = heightRecursively(root.getLeft());
			rightHeight = heightRecursively(root.getRight());
			if (leftHeight > rightHeight)
				return leftHeight + 1;
			else
				return rightHeight + 1;
		}
	}

- Vir Pratap Uttam May 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int height(struct node* node)
{
if (node==NULL)
return 0;
else
{
/* compute the height of each subtree */
int lheight = height(node->left);
int rheight = height(node->right);
if (lheight > rheight)
return(lheight+1);
else return(rheight+1);
}
}

- SachinGuptaMNNIT June 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you can't reconstruct a tree with 100% certainty if you are given preorder and postorder, consider a tree that has left only or right only sub-trees then you can have the same preorder and postorder for two different trees.

- Anonymous March 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you can't reconstruct a tree with 100% certainty if you are given preorder and postorder, consider a tree that has left only or right only sub-trees then you can have the same preorder and postorder for two different trees.

- santaf March 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Frequently asked adobe question: Given a preorder and post order traversal construct a tree
anandtechblog.blogspot.com/2011/06/construct-given-tree-from-pre-order-and.html

- Anand June 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey67319" class="run-this">int height(node *head){
if(head==NULL)
return 0;
return max(height(head->left),height(head->right));
}</pre><pre title="CodeMonkey67319" input="yes">
</pre>

- Anonymous July 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

height_of_tree(temp)
{
if(temp==NULL)
return 0;

left=height_of_tree(temp->left);
right=height_of_tree(temp->right);
return (1+max(left,right);
}

- maverick! July 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Code for n-ary tree

public static void nAryTreeHeight(Node n) {
		if(n==null) {
			return 0;
		}
		int mh = 0;
		for(Node c : n.getChildren()) {
			mh = Math.max(mh, nAryTreeHeight(c) );
		}
		return mh+1;
	}

- dmr August 05, 2016 | 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