Amazon Interview Question for Software Engineer in Tests






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

get a inorder traversal and either post order or pre order traversal.
Now start creating the new tree but in reverse order of traversals... your post order traversal will become preorder traversal and vice versa........

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

temp = T->left
T->left = T->right
T->right = temp

Recursively call the above method on T->left and T->right.

- Messi April 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tree* copyMirror(Tree* root)
{
if(!root) return null;
Tree* root1=(Tree*)malloc(sizeof(Tree));
root1->data=root->data;
root1->left=null;
root->right=null;
if(root->left)
root1->right=copyMirror(root->left);
if(root->right)
root1->left=copyMirror(root->right);

return root1;
}

- newlifeseattle April 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void mirror(struct node *p)
{
struct node *temp1;
if(p != NULL){
mirror(p->left);
mirror(p->right);
temp1 = p->right;
p->right = p->left;
p->left = temp1;
}
}

- Anonymous April 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Formated properly

void mirror(Node **root)
{
      if(*root==NULL) return;
       Node * temp = NULL;
       mirror(*root->left);
       mirror(*root->right);
       temp = *root->left;
       *root->left=*root->right;    	
      *root->right = temp;	

}

- Mayank April 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

TreeNode Mirror(TreeNode root)
{
        if(NULL == root) return root;
      
       TreeNode temp = root->left;
       root->left= Mirror(root->right);
       root->right = Mirror(temp);
       return root;
}

- ankushbindlish May 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct node {
   int value;
   struct node* left;
   struct node* right;
};
typedef struct node* NODE;

NODE CopyTree (NODE root) {
  if (root == NULL)
    return NULL;
  NODE subroot = GetNode();
  subroot->value = root.value;
  subroot->left = CopyTree (root->left);
  subroot->right = CopyTree (root->right);
  
  return subroot;
}

- Anonymous February 21, 2013 | 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