# Microsoft Interview Experience for Internship

Recently Microsoft visited our campus for internships. They had a coding round which was followed by 3 interviews ( 2 technical and 1 HR).

Online Test: It was conducted on mettl and we had 90 minutes to solve 3 questions. Questions were shuffled for everyone but were fairly easy.

1. Given a string we need to return a string in which each character should be increased by 3 units.

Eg.

```adz -> dgc
```

The a becomes d, d becomes g and z becomes c. The only trick here was that we just had to complete the given function and they passed the string as a character pointer and so you need to see how to traverse a string represented as a character pointer.

2. Convert an infix expression to postfix expression.

3. Given a string in form of num1+num2=num3 in which one of them is X we need to find the value of X.

Eg.

```Input : 5+X=7
Output: X= 2
Input : 7+2=X
Output: X=9
```

So this was basically an implementation based question and we just needed to find out of which one of them was X and accordingly find the answer.

48 students were selected for the interviews.

Round 1: I was asked 3 questions in this round. The questions were pretty easy.

1. Find the max and min element at any point in a stack. I was asked to code it. I tried to keep the interview interactive by telling him my approach as I wrote the code. I was asked to do a few dry runs, and he seemed satisfied with my approach.
2. Reverse a string. We discussed the stack question for about 20 minutes and I told him I will use a stack to reverse it, and he didn’t ask me to optimize it.
3. Mirror a given Binary Tree. I first told him my approach that we will use post-order traversal and then he asked me to code it.

I answered all the questions, so I was pretty confident that I will be selected for the next round.

Round 2: I was asked just 2 questions in this round.

1. Find the diameter of a tree (No. of nodes on the longest path in a tree). I had seen this question before and knew the solution so I just told him my approach and we did a few dry runs on sample inputs before proceeding to the next question.
2. Given a number N we need to convert N to 1 by performing a minimum no of operations. The allowed operations are:
• Subtract 1 from a number.
• Divide the number by 2.
• Divide the number by 3.
• Eg.

```Input: 10
Output: 3
10->9->3->1
```

So at first, I was trying to generalize the solution by taking different cases. The interviewer asked me to change my approach and I thought of a Dynamic Programming approach.

## C++

 `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``int` `n = 10; ` `     `  `    ``int` `dp[n + 1]; ` `    ``dp = 0; ` `    ``dp = 1; ` `    ``dp = 1; ` `    ``for``(``int` `i = 4; i <= n; i++) ` `    ``{ ` `        ``dp[i] = dp[i - 1] + 1; ` `        ``if``(i % 2 == 0) dp[i] = min(dp[i], 1 + dp[i / 2]); ` `        ``if``(i % 3 == 0) dp[i] = min(dp[i], 1 + dp[i / 3]); ` `    ``} ` `    ``cout<

Output:

`3`

Round 3(HR): So it started with questions like tell me about yourself. I was prepared for this question and I kept the focus on my coding skills. For me, it was a mix of HR and technical round.

So, he asked me questions on Doubly Linked List. Given a pointer to a random node of a doubly linked list. Delete the node.

We discussed all the edge cases involved, and he just asked me to code it mentally and tell him each line. He seemed satisfied. Then he asked me why I wanted to work at Microsoft.  It was followed by questions on OOPS and Hashing.

He asked me what was the implementation of hashing in real life and how hashing is implemented internally. I was able to answer this but I didn’t know the technical terms. Finally, he asked me if I had any questions for him. Never give a no as an answer to this question as it shows that you are not interested in knowing about the company.

Verdict – Selected

Write your Interview Experience or mail it to contribute@geeksforgeeks.org My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

1

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.