Amazon Interview Question


Country: United States




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

It's not mirror image.

- words&lyrics July 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

then what it ll do....m nt getting xact ans

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

dont have exact ans bt its not the mirror tree

- codinglearner August 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is what it doing

Input

                           4
			2    5
	              1        7

After completing swapping at 2

                            4
                      2         5
                           1        7

Swapping at 4 

                           4
                    5              2
                        7              1

Swapping at  2
   
                             4
                 5                       2
                       7            1

  This is mirror image of structure but not data.

- hari@hbiz.in August 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 3 vote

4 Answers
void Func(tNode **node){
if(*node!=NULL){
Func(&(*node)->pLeft);
tNode *temp;
temp = (*node)->pLeft;
(*node)->pLeft= (*node)->pRight;
(*node)->pRight = temp;
Func(&(*node)->pLeft);
}
}
will create a mirror image.
The above code will just swap root node's Left and Right child.

- piyush August 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

u are right.. the given code just swap root node's left and right child

- cobra August 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

+1, Yes this code will swap the left and right child of Root node.

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

It creates a reflection of the tree as stated above

- Struggler July 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thank u guys bt
Let the input given be
98,15,100,10,78,120,5,12,96,110

What would be the output of the following code snippet?

int main(void)
{
tree *bT = new tree;
int i = 10;
int data;
while(i--){
std::cout<<"Enter the node"<<std::endl;
std::cin>>data;
bT->InsertNode(bT->GetRootNode(), data);


}

bT->Func(bT->GetRootNode());
bT->InsertNode(bT->GetRootNode(), 99);
bT->Func(bT->GetRootNode());
bT->traverse(bT->GetRootNode());
}
// insert() is simple bst insert and traverse() is postorder traversal

- Let the input given be 98,15,100,10,78,120,5,12,96,110 and after calling func(root) nd doing post order traversal what shoul be o/p July 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It absolutely does not creates an mirror image of the tree...

- amnesiac August 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Imagine each parent node as a hinge about which child nodes rotate.
2. First, the leaf nodes rotate about their parent node. Then the level above leaf nodes rotate about their parents and so on.

- weird August 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

It creates a mirror of tree , or swaps the children.

- Zee July 31, 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