Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

We need to remove two edge with least weight. Here is how we can do this:
Traverse the tree breadth wise (use queue). Keep two variable to store MinNode1 and MinNode2. At the end remove the two least weight edge.
Pseudo code:
1. Queue.enqueue(root)
2. while (!queue.Empty())
2.1 poppedNode = queue.dequeue();
2.2. if(poppedNode->Left != null) queue.enqueue(popped->left);
2.3. if(poppedNode->Right != null) queue.enqueue(popped->Right);
2.4 if ( popped->Wt < = Max(minNode1->Wt, maxNode->Wt))
Swap (larger(minNode1, minNode2), popped);

At the end, remove the link : minnode1->parent and minnode1->parent

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

Can we use max heap structure to get the max heap twice we will get three trees each will have max edge values.

- bala December 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

Clearing Ambiguity and responding to this question here.

Certainly we need to assume that the tree Has to be Binary Tree to be possible. So the algo goes here.

We need to create a Binary Tree on the basis of edge weight value as node and do the following operation.

1> For Unorder Binary Tree, we need to traverse the full tree to get the following values
a> Smallest Edge Node Value and Second Smallest Edge Node Value. As node is now edge.
b> Total Weight of the Tree
So the Max value will be Total minus the two smallest Node value and there will be three sub tree.
Time Complexity will be O(n) and Space O(1).
2> For Ordered Binary Tree like BST the algo remain the same only the Time Complexity goes to O(log n) as searching for the two smallest edge will be easier.

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

* The tree need not be a binary tree. A multiway tree wil also yield 3 trees when 2 edges are removed
* Binary Search Tree does not specify any ordering on the weights of its edges

Correct me if I am wrong!

- IAmIronMan July 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please elaborate more with example.

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

input to program is a tree.. output should be 3 trees with each tree having maximum weight..

- ritesh.bajaj6 December 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

how it is possible??? sum of the weight of all nodes of all the three tree is constant.... if one tree have max weight and other two should not have maximum weight

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

@cobra: you are absolutely right. had the same doubt. funny that the people have come up with solutions to a question that doesn't sound at all right

- The Artist December 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@cobra, @theArtist => Weights are for edges and not vertices. After you remove 2 edges from the tree, how do you think sum of weights will still be equal to the remaining trees weights. Hope you understood the problem.

- vikram January 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

This question is ambiguous. We can't always break a tree into three trees by removing two edges. Consider the following example:

A->B
A->C
A->D
A->E
A->F

In this case even after removing two edges, there will be only one and one tree

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

ha ha!! if you remove two edges, there will be two trees with one node each and one tree with remaining nodes :)

- cobra December 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

Such questions are expected from Microsoft only. I hate them.

- gitesh.adobe February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

max flow min cut theorem

- smashit December 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

This question is very ambiguous. Can someone clarify this question.?

- newlearner December 28, 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