Amazon Interview Question for Software Engineer / Developers






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

hi

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

Do breadth first traversal and keep on storing the children in next and next->next and update the prev pointers.
Problem here is we will use a queue to BFT, it may not be accepted.

- SG May 03, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This can be done in inorder traversal , without any need for additional queue.

- Anonymous December 16, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the code to convert a binary tree to a single link list. Now in order to convert it to a doubly linklist we simply need to scan it once and assign prev pointers....


void main()
{
tree_node * temp = root;
while(temp->left)
temp=temp->left;
convert_to_linklist(root);
root = temp;
//siblinglink(root);

while(root->right)
{

printf("value is %d\n", root->val);
root = root->right;
}
printf("value is %d\n", root->val);
}
void convert_to_linklist(tree_node * root)
{
if(!root)
return;
tree_node * temp = root->left;
if(temp)
{
while(temp->right)
temp = temp->right;
temp->right = root;
temp = root->left;
root->left = NULL;
convert_to_linklist(temp);

}

temp = root->right;
if(temp)
{
while(temp->left)
temp = temp->left;
tree_node * te = root->right;
root->right = temp;
convert_to_linklist(te);

}
}

- gauravk.18 April 06, 2008 | 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