Amazon Interview Question for SDE-2s


Country: India
Interview Type: In-Person




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

Most probably this qus is for tree/graph right?

- PKT March 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use Kth order statistics to get the first K elements near to it..

- nathgopi45 March 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Scan the tree to look for the node and push all parent nodes encountered in the path to a stack S
2) Write a function to find nodes at K distance which are child of this node (simple DFS). Lets call that function kChild(node)
3) Now pop the parent of the node and find out the k -1 distance child nodes of it.
4) Repeat the process till the stack is empty.

- kr.neerav March 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void findbelow(struct tnode *root,int level,int k)
{
     if(root==NULL)
        return;
     if(level==k)
     {
        printf("%d\t",root->val);
        return;
     }
     findbelow(root->left,level+1,k);
     findbelow(root->right,level+1,k);
}

void findabove(struct tnode *root,struct tnode *node,int level,int k)
{
     static int vector=0;
     if(root==NULL)
        return;
     findabove(root->left,node,level+1,k);
     findabove(root->right,node,level+1,k);
     if(root==node)
        vector = vector | 1<<level;
     if(vector & 1<<(level+k))
     {
        vector = vector ^ 1<<(level+k);
        printf("%d\t",root->val);
     }
}

- Nitin April 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

BFS should do the trick!

- huh June 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

use this one
suppose pointer *p is in current position

p=p + ((k * sizeof(struct node) ) - (k * work_size));

- istiyak916 March 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

????????????????????????

- Anonymous March 24, 2014 | Flag


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