Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

boolean same_tree (TREE * head1, TREE *head2 )
{
          if((head1 && !head2) || (head2 && !head1))
                   return false;
          else
          {
                 if(head1->data == head2->data )
                 {
                             return (same_tree(head1->left,  head2->left ) && 
                                         same_tree(head1->right, head2->right))
                 }
            }
           return false;
}

- Shivaprasad April 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Needless to say the question is too easy I guess the interviewer was not prepared

- RohitDumbre86 April 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Maybe If there is no constrain.

- Red Lv April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can enhance this question if we say if two trees have billions of nodes how will you compare.

- RohitDumbre86 April 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

just find the inorder and preorder of both tree and compare both the array ..if same tree is same otherwize not..

- jai April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

its wise to use level order traversal and compare each time.

- RohitDumbre86 April 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

its wise to use level order traversal and compare each time.

- RohitDumbre86 April 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

other than recursion if no extra space is allowed, might also make it slightly complicated

- Dr.Sai April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) If both trees are empty return false
2) else if both trees are non-empty
a. check data of root nodes
b. check left sub tree recursively
c. check right sub tree recursively
3 Else return false

int sametree(struct node *t1, struct node *t2)
{
if(t1->data == NULL) && (t2->data==NULL))
return 0;
else if(t1->data!=NULL && t2->data!=NULL)
{
return (t1->data == t2->data) &&
sametree( t1->left,t2->left) &&
sametree(t1->right,t2->right);
}
else
return 0;
}

- sai25590 April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

garimaa.blogspot.in/2012/04/program-13th-in-c.html

- Solution by tree level traversal April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

check the down one pls

- Anonymous April 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

garimaa.blogspot.in/2012/04/program-13th-in-c_11.html

- Solution by tree level traversal on April 11, 2012 April 11, 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