Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

.leetcode.com/2010/11/convert-binary-search-tree-bst-to.html

- begineer July 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

cslibrary.stanford.edu/109/TreeListRecursion.html

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

public TreeNode[] linkSubTree(TreeNode root) {
TreeNode[] pair = new TreeNode[2];
if (root.left.left == null && root.left.right == null) {
root.left.right = root;
pair[0] = root.left;
} else {
TreeNode[] leftSub = linkSubTree(root.left);
pair[0] = leftSub[0];
root.left = leftSub[1];
leftSub[1].right = root;
}
if (root.right.left == null && root.right.right == null) {
root.right.left = root;
pair[1] = root.right;
} else {
TreeNode[] rightSub = linkSubTree(root.right);
pair[1] = rightSub[1];
root.right = rightSub[0];
rightSub[0].left = root;
}
return pair;
}

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

struct tree_node
{
	int data;
   struct node * left;
   struct node * right;
};

typedef struct tree_node * ptr_to_node;

ptr_to_node root=NULL;
ptr_to_node head=NULL;
ptr_to_node temp2;

void convertolist(ptr_to_node temp)
{
	if(temp->left !=NULL)
   	convertolist(temp->left);
   if(head==NULL)
   	head=temp2=temp;
   else
   {
   	temp2->right=temp;
   	temp->left=temp2;
      temp2=temp;
   }
	if(temp->right !=NULL)
   	convertolist(temp->right);
}

- Varun Varunesh July 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In order traversal and build linked list

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

simple jst traverse inorder and for any node make left node as inorder predecessor and for right node point it to inorder successor

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

TreeNode * ConvertToDoublyLinkedList(TreeNode * root)
{
if(NULL == root)
return NULL;

TreeNode * left = ConvertToDoublyLinkedList(root->left);
// root's left is the rightmost element of the left sub tree
TreeNode * leftTemp = left;
while(leftTemp && leftTemp->right)
leftTemp = leftTemp->right;
root->left = leftTemp;

if(leftTemp)
leftTemp->right = root;

TreeNode * right = ConvertToDoublyLinkedList(root->right);
// root's right is the leftmost element of the right sub tree
TreeNode * rightTemp = right;
while(rightTemp && rightTemp->left)
rightTemp = rightTemp->left;
root->right = rightTemp;

if(rightTemp)
rightTemp->left = root;

return root;
}

The final root points to the actual root in the BST. you can traverse left or right to reach the front or the end of the doubly linked list.

I am using the "left" and "right" members for the "prev" and "next".

- Gautam July 22, 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