Komli Media 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

Use order stastistics , at every node left count is given

- richa.shrma.iitd March 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 3 vote

::Reverse In-order traversal::
int Klargest(struct node* root,int k)
{
int static count=0;
Klargest(root->right ,k);
if(++count==k)cout<<root->value;
Klargest(root->left,k);
}

- Anonymous March 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

If you reverse inorder then what will be its complexity?

- King@Work March 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

:(

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

If deletion is allowed, we can do the following

findKthMax(Node t){

maxCount = 1;
Node maxNode;
while(maxCount <= k ){

maxNode = max(tree);
deleteNode(tree,maxNode)
maxCount++;

}

return maxNode;

}

max(Node tree) and deleteNode() have O(logN) complexity, and the algo has O(klogN) = O(logN) complexity

}

- random March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If K is 1, this will be O(NlogN)?

- mtsingh March 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

please ignore my comment

- mtsingh March 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

are u deleting from a max-heap ??

- Jane March 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wont this print n-k th largest element ?
cuz u r deleting first K largest elements.. so next biggest will be n-kth element.

- V March 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@V :
I accept that I have written a crappy code but you should think before writing.
Suppose there are 5 elements - 1 , 2 , 3, 4 , 5 . In this, wont the 4'th largest be 2, or will it be 4 by your dumb logic !!

- mtsingh March 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think this can be done in O( H ) , H = height of BST
But that would require every node of the tree to have following information:
1)number of nodes smaller that that node

Assuming we have this info. then we start at root and
1)if k > number of nodes smaller that this node ,we move to its right child
2)else if k < number of nodes smaller that this node ,we move to its left child
3) else if k == number of nodes smaller that this node , this is the node we are looking for

but again to get the required info, we have to first traverse the tree in inorder fashion , which is of order O(n).
so without the above mentioned info , i think , we cant do it in O(h).

- Anurag Gupta April 20, 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