Microsoft Interview Question for Software Engineer / Developers






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

You must have done well to get to the Director. I assume he was the last person in the loop.

- Anonymous December 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yeah well i didnt get the job :(, i was interviewing for New College grad position in Tools and Server Division with Windows Workflow Foundation team of .Net Framework.

- sachin323 December 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry to hear that.

- Anonymous December 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool Search (Node *root, int key)
{
   while (root != NULL)
   { 
       if (root-> no == key) {return true;}
       else if (root->no > key) {root = root->right;}
       else {root = root->left; }   
   }
   return false;
}

Node * LowestCommonAncestor(Node *root, int a, int b)
{
      if (root == NULL) {return ; }
            
      if (a < root-> no && b > root->no )
      {
         if ( Search(root->left, a) && Search(root->right, b) )
         {
              return root;
         }
         else
         {
              return NULL;
         }
      }
      else if ( a < root-> no && b < root-> no)
      {
         return LowestCommonAncestor(root->left, a, b);
      }
      else if ( a > root-> no && b > root-> no)
      {
         return LowestCommonAncestor(root->right, a, b);
      }
      else
      {
         return NULL;
      }              
}

- r.ramkumar December 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

one clarification:
one check is missing:
OLD :
if (a < root-> no && b > root->no )
SUGGESTED:
if ((a < root-> no && b > root->no ) ||
(a > root-> no && b < root->no ))
{
SAME CODE
}
else-part is SAME as written by you

- jyt December 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

One more clarification *small one*
This is in Search Function : 2nd if-check is incorrect

bool Search (Node *root, int key)
{
while (root != NULL)
{
if (root-> no == key) {return true;}
else if (root->no < key) {root = root->right;}//CHK
else {root = root->left; }
}
return false;
}

- jyt December 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Above code will only work for BST and will not work for every "Binary Tree"

- Krishna December 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I took a while to reach to ans as this was binary tree , the solution i had given there was
1) get preoder and inorder
2) take first element in prorder and search it into inorder all the element to left of it is left subtree and on right are right subtree

3)find the index of node1 and node2 in inorder , if one appears on the left of root and other on the right then return root as ans

4) if both appear on left side , discard all the elements right to root , same with if they appear on the right of root

5) increament index in preorder

6) continue this recursively

- sachin323 December 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your solution is good, but you are using extra space O(n) for Preorder + O(n) for Inorder totally O(2n). Interviewer might expected solution without using extra space . Below I provided a solution without using extra space & time complexity O(n).

- siva.sai.2020 December 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

node * LCA(node *n1,node *n2,node * root) {
if (!root || !n1 || !n2) return null;

if ((n1->val <= root->val) && (n2->val > root->val)) return root;
else if (n1->val > root->val) return LCA(n1,n2,root->right);
else if (n2->val < root->val) return LCA(n1,n2,root->left);
}
Above code is for BST and with assumption that :
n1->val < n2->val
n1 and n2 are present in the BST

- jyt December 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

well is have specifically quoted that its a "binary tree" not a Binary Search Tree .

- sachin323 December 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef  struct node{
       int val;
       struct node *left;
       struct node *right;
} tNode;

tNode * ClosestCommonAnscestor( tNode *root, tNode *key1, tNode *key2)
{
     if( root == NULL )
     {
             return NULL;
     }
     else if( root == key1 || root == key2 )
     {
           return root;
     }
     else
     {
         tNode *l= NULL, *r = NULL ;
         
         l = ClosestCommonAnscestor( root->left, Key1, key2 );
         r = ClosestCommonAnscestor( root->right, Key1, key2 );
         if( (l != NULL)  && (r != NULL) )
         {
               return root;
         }
         else
         {
               return l ? l : r;
         }
     } 
}

If you find any mistakes in my code please let me know.

- siva.sai.2020 December 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

your space complexity is not O(1), because it implicitly use stack (recursive call), so it is O(log(n))

- Anonymous February 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you need to add one more condition in else block like

else if (l == null && r == null)
return null

and then

else return l ? l: r

- hari August 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

hey sachin, i have an interview with Server and Tools as well. could you please tell me some of the other questions you were asked? I would really appreciate your assistance.

Best,
DK

- DK December 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i have put all the questions on CC . Apart from that no other serious questions were asked just some causal talking about team and what i like to do

- sachin323 December 12, 2010 | 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