# Microsoft IDC Interview | Set 35 (On-Campus for Internship)

Online test: This test was organized by cocubes.com, and had to be completed within an hour.

There were two coding questions:

1. There is a linked list whose node is defined as follows

```    struct node
{
int x,y;
node* next;
};```

We had to implement a function which takes the head of linked list, and if any three consecutive points lie on same horizontal or vertical line, we had to remove the middle node. The linked list will either be empty or will contain atleast two nodes. The function prototype was:

```    void remove(node* head)
{

}```

Example:

```Input: (1,2)->(2,3)->(2,4),(2,5)->(3,4)
Output: (1->2)->(2,3)->(2,5)->(3,4)```

2. Given a sorted array, convert it into a height balanced binary search tree. A height balanced tree is one in which for every node, the height difference of left and right subtree is at most 1. Node of binary tree was:

```    struct node
{
int data;
node* left;
node* right;
};```

Function to be implemented was:

```    node* binary_tree(int* ar, int len)
{

}```

Interview:
There were 3 rounds of interview, and we had write code on paper.

Round 1:
There were two questions:
1. Given a string, remove all continuous occurrences of ‘a’ and any occurrence of ‘b’.
Example: Input: “aacbccdbsssaba”, then output: “acccdsssa”

2. What data structure should be used if we have to implement insert and delete functions in a text editor? The functions should be as fast as possible.

Round 2:
Question 1: Given a string and two positions in that string, shuffle the string, that is, move the given substring to the front. Example:
Input: abcdefgh, 4,6
Output: defabcgh
This has to be done inplace with O(n) time complexity.

Question 2: How to implement dictionary data structure in C++? What kind of hash functions shall we use? How to manage collisions?

Question 3: How would you implement vector data structure in C++ on your own? What would be the accessing time complexity? How can you make it O(1)? How to resize the structure?

Round 3:
Question 1: Given a k-ary tree, how to print the elements layer wise?

Question 2: Given a singly linked list and a number ‘n’, write code to reverse every ‘n’ elements of the linked list. Example:
Input: 1->2->3->4->5->6, n=3
Output: 3->2->1->6->5->4

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

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