Amazon Interview Question for Developer Program Engineers


Country: India




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

int sumUp(node *p){
int curr = p->data;
int left, right;

if( p-> left != null)
left = sumUp( p->left );
else
left = 0;

if ( p->right != null )
right = sunUp(p->right);
else
right = 0;

p->data = left+right;
return curr + p->data;
}

- n14h1l February 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is perfect works fine.

- sanjay537 February 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Below is my recursive solution to the problem

public int sumLR(Bnode root)
{
int temp=0,sum=0;

if(root==null)
return 0;

temp=root.getData();
sum=sumLR(root.getLeft()) + sumLR(root.getRight());

root.setData(sum);

return temp+sum ;


}

- Free Bird February 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

int getvalue(BST *a)
{
	//if(a==NULL) return 0;
	int value = a->data;
	a->data = 0;
	if(a->leftchild) a->data+=getvalue(a->leftchild);
	if(a->rightchild) a->data+=getvalue(a->rightchild);
	return a->data+value;
}

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

1. 20 & 30 are left and right child of 10
2. 40 & 50 are left and right child of 30

- sumit February 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is Converting a tree to a SumTree problem

- Srishti February 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

solution(BT root)
{
root.data = sumandzero(root);
}
public static int sumandzero(BT root)
{
int k=root.data;
if(root==null)
return 0;
if(root.left==null&&root.right==null)
{

root.data=0;
return k;
}
k+=sumandzero(root.left);

k+=sumandzero(root.right);
return k;
}

- jasmeet@iastate.edu February 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int getvalue(BST *a)
{
//if(a==NULL) return 0;
int value = a->data;
a->data = 0;
if(a->leftchild) a->data+=getvalue(a->leftchild);
if(a->rightchild) a->data+=getvalue(a->rightchild);
return a->data+value;
}

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

int getvalue(BST *a)
{
//if(a==NULL) return 0;
int value = a->data;
a->data = 0;
if(a->leftchild) a->data+=getvalue(a->leftchild);
if(a->rightchild) a->data+=getvalue(a->rightchild);
return a->data+value;
}

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

int getvalue(BST *a)
{
	//if(a==NULL) return 0;
	int value = a->data;
	a->data = 0;
	if(a->leftchild) a->data+=getvalue(a->leftchild);
	if(a->rightchild) a->data+=getvalue(a->rightchild);
	return a->data+value;
}

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

int getvalue(BST *a)
{
	//if(a==NULL) return 0;
	int value = a->data;
	a->data = 0;
	if(a->leftchild) a->data+=getvalue(a->leftchild);
	if(a->rightchild) a->data+=getvalue(a->rightchild);
	return a->data+value;
}

- Di February 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

int cumulativetree( NODE* root )
{
	if( root == NULL )
		return 0;
	if( root->left == NULL && root->right == NULL ){
		temp = root->data;
		root->data = 0;
		return temp;
	}
	return (root->data += cumulativetree(ptr->right) + cumulativetree(ptr->left));
}

- y2km11 February 23, 2012 | 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