Amazon Interview Question for Software Engineer / Developers






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

easy... just for each parent do a right rotation and at the same time set prev of parent to left child(if any).

- mrn July 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

do a in-order traversal, with head and tail pointers.

struct node {
	int data;
	node * left;
	node * right;
	node(int a) {
		data=a; left=NULL; right=NULL;
	}
};

node * head=NULL, * tail=NULL;
int cnt;

void bsttodll(node * root) {
	if(root==NULL) return;
	bsttodll(root->left);
	if(head==NULL) {
		head = root;
		tail = head;
	} else {
		root->left = tail;
		tail->right = root;
		tail = root;
	}
	bsttodll(root->right);
	return;
}

int main (int argc, char const* argv[]) {
	
	node * root = new node(7);
	root->left = new node(4);
	root->right = new node(10);
	root->left->left = new node(3);
	root->left->right = new node(5);
	root->right->left = new node(9);
	
	bsttodll(root);
	
	return 0;
}

- jack July 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int the in order traversal of bst...make following changes..
inorder(root,first,last){
if(root==null)
return null;
inorder(root->left,first,last);
if(last==null)
{
last=first=root;
}
else
{
last->right=root;
root->left=last;
last=root;
}
inorder(root->right,first,last);
}

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

i think it is pretty easy :) just do the inorder traversal and accordingly change
see this --
void BSTtoDLL(struct node *r,struct node **head,struct node *prev)
{
if(!r)
return;
BSTtoDLL(r->left,head,prev);
if(!*head)
{
*head=r;
}
else
{
r->left=prev;
prev->right=r;}

prev=r;

BSTtoDLL(r->right,head,prev);
}

where the head is head of linked list

- geeks July 18, 2011 | 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