Sunday, March 9, 2008

Microsoft Fresher Interview Experience

First Interview:

The interviewer initially asked me all about my internship project and my role in that.

1. Given an Ellipse class can you derive a Circle class from it?
What all methods would you include in the circle class and what all in
ellipse?
Design a class of curve from which Circle and Ellipse can be inherited.


2. This contained series of questions on C++.

  • What are virtual functions? Why are they used? Give examples.
  • What are pure virtual functions and abstract classes? When do we use it?
  • Where are virtual functions stored in the memory? How does the object knows that the virtual function to be called is from base class or derived class?
  • What is VTable (virtual table) and what does it do?
  • Few more similar questions that I am not able to remember.


3. These were also series of Questions mostly on OS skills:

  • What are DLLs? Why do we use them?
  • How does DLL work? Can anybody call methods written in DLLs ?
  • What are static and shared Library? Which is fast and why?
  • Questions about paging, loading, linking etc.
  • Concept of 32-bit OS, virtual memory, inter-process communication etc.
  • Few more similar questions that I am not able to remember.


4. Given a BST (Binary search Tree) how will you find median in that?

Constraints:

  • No extra memory.
  • Function should be reentrant (No static, global variables allowed.)
  • Median for even no of nodes will be the average of 2 middle elements and for odd no of terms will be middle element only.
  • Algorithm should be efficient in terms of complexity.


Write a solid secure code for it.

Second Interview:

Again, the interviewer asked me about my internship project and my role etc stuff.

1) He gave me a question that suppose you are getting an infinite binary stream of characters then after any point of time you need to print whether the no is divisible by 3 or not, how will you do that?

I was bit confused. I asked him that how are we getting the stream? Then he told me that you take a function signature as:


char getStreamBit();



which will return you the bit character (either '1' or '0') one by one. Also in the end he asked me to write the code of my algorithm on the board.

2) Then he asked me if I have any questions? I asked about 2-3 questions.

He was in hurry, so he left after that.

First and Second interview
together lasted for JUST 1 hour and 45 minutes.

Third Interview:

Again, he too asked me about my internship project, implementation, my role etc.

1. Modified 2 color sort problem i.e. you are given an array of integers containing only 0s and 1s.You have to place all the 0s in even position and 1s in odd position. And if suppose, no. of 0s exceed no. of 1s or vice versa then keep them untouched. Do that in ONE PASS and without taking extra memory (modify the array in-place).

For Example :

Input Array: {0,1,1,0,1,0,1,0,1,1,1,0,0,1,0,1,1}

Output Array: {0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1}

Write a solid secure code for it.

2. You are given a Linked List and a function declaration as node* KReverse(node* head, int k);

KReverse is a function that reverses the nodes of a Linked List k at a time and then returns the modified Linked List.

For Example

Linked List : 1->2->3->4->5->6->7->8->9->10->11

For k = 2

Return Value: 2->1->4->3->6->5->8->7->10->9->11

For k = 3

Return value: 3->2->1->6->5->4->9->8->7->10->11

Write a solid secure definition for the function KReverse.

Constraints:

  • If the no. of nodes in a link list is not a multiple of k then left-out nodes in the end should remain as it is.
  • You have to retain the memory address of the nodes without modifying it i.e. you can't just interchange the values in the nodes.
  • No extra memory allowed.


He tested some of his inputs with the code I wrote.

The third interview lasted for about little more than 1.5 hrs and in the end he also offered me some fruits (Apple, Guava etc) and asked me about my college etc.

Fourth Interview:

I had my fourth interview too.

1. Initially he asked me about my earlier interviews. Who were your interviewers, how did you perform etc. things. I told him that in my first interview I just made a small mistake writing code (median of BST under constraints) for one of the case. So he asked me to complete my code for that case too and write solid secure code only.

He was very very particular about the code rather than the problem solving aspect for this question. He was basically checking my concepts about pointers, memory allocation etc things in whole interview and my way of writing code.

2. Suppose you are passing a string to a Formatter function. Get the formatted news feed output string such that

  • There should be one sentence per line.
  • There shouldn't be any spaces i.e. the line shouldn't be blank.

For example:

Input String:

". ....West Indies reached the final of DLF series. .Lalu was invited
to IIM-A once again. . .. .. . Microsoft unveils Zune, an ipod killer. .
. . . "

Output String:

"West Indies reached the final of DLF series.
Lalu was invited to IIM-A once again.
Microsoft unveils Zune, an ipod killer."

Design and write solid secure code for the Formatter Function.

As I said earlier, he was very particular about the code. This is where you need to follow all the standards, convention and check for the test cases. He just wanted to check my concepts about the pointers, memory allocation, OS etc stuff and of course the logic proposed by me for this particular problem(and questions like how much extra memory do you need for the output
string, how can you reduce that etc, complexity etc things)

He then asked me to give some of the test cases for the input string.

In between, he kept me asking questions like what if type int(32 bit) is replaced with type int64 (64bit). What modifications will you make to your code. Questions about double pointers, segmentation fault, all conceptual questions again!

Then he asked me about my interests. Why should we hire you etc HR questions. If you have any questions etc. stuff