Microsoft Interview | 15
I recently had interview with Microsoft and i have been selected.
I am really thankful to geeksforgeeks site which provides preparation material for technical interviews at one place. And credit of my selection also goes to my friend “Ankit Tripathi” who helped me a lot in my preparation.
I have attached my interview experience file with this mail.
Written Test: 30 MCQs based on Algorithms & logical aptitude and 2 coding problems.
Telephonic Interview: All questions related to your resume & projects and some behavioral questions.
Round 1:
Ques1. Write code for run -length encoding of a given string in-place (without using any extra memory).
Sample Input: aaaaaaaaaabcccccc
Output: a10bc6
Ques2. Write code for a function which converts a given integer to a string. (Use only one for-loop).Check for all the boundary cases.
Ques3. Suppose you are going to organize a party from 9:00 am to 20:00 pm. You have invited ‘n’ number of guests for the party. You are given the arrival time and the departure time of all guests. Every time a new guest arrives, you give him a glass of wine and when he leaves, you take the glass back. If someone has left and returned the glass, you can give the same glass to a new guest who has just arrived.
Based on the given schedule for guests, determine the minimum number of glasses required for the party. A guest can come or leave at any time, but you are given the fixed schedule. Write code for the given problem.
Round 2:
Some questions related to resume and subjects studied in the curriculum.
Ques1. How can we do a Tree Traversal without using a stack (not even the stack for recursion). Write code for an in-order traversal without using stack. What would be the changes in the function if we want to do a pre-order or post-order traversal?
Ques2. Write code for finding loop in the singly linked list and fixing it.
Ques3. Given a linked list with two pointers, one is next pointer and another is a random pointer which can point to any node in the list (forward, backward or itself), you have to make a copy of this list without tempering the original list. Write the code for the same in O(n) time complexity.
Round 3:
Ques1. Give different possible approaches for Checking whether two strings are anagrams (with and without using hash tables). What are the possible advantages and drawbacks of each approach? Write code for the approach which involves first sorting the two strings and then matching character by character (O(nlogn) approach). Which sorting you will use and why? Write test cases also.
Ques2. Write code for counting the number of inversions in an array in the minimum time possible. What could be different possible approaches?
Ques3. Given two huge numbers represented as linked list, write a function to add them and return a number in the same format.
Ex: 950 represented as 9->5->0->NULL
150 represented as 1->5->0->NULL
then, the output should be 1->1->0->0->NULL
Ques4. We have ‘n’ people in a party, out of whom only one can be a celebrity. And he may or may not be present in the party. A celebrity is known to everyone but he does not know anyone. All other person may or may not know each other. If a person ‘A’ knows ‘B’, it does not implies that ‘B’ also knows ‘A’. You can ask only one question to someone ‘Do you know this (‘X’) person?’ and he can only reply in YES or NO. Your job is to find the celebrity in minimum number of questions.
Round 4:
First he asked general questions from resume.
Ques1. Write code for finding the least common ancestor of two given nodes in a binary tree. ( both recursive and iterative approach).
Ques2. Which data-structure you will use for implementing the ‘malloc’ and ‘free’ functions? (You have been given with a pointer which points to a large chunk of memory).Write full codes for implementing these two functions.
Each face-to-face round duration was approximately 1 hour. Results were declared after 4 days of interviews. Every interview was an eliminating round. Questions were not very hard but they were very keen on accuracy and efficiency of code (it should run on all possible input cases).
This article is compiled by Monika Bisla. Many Many congratulations to Monika for her selection. 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.
Anyone know how to do the run-length encoding without extra space?
I'm assuming that means you can't create another string to put your answer in.
We can use two passes,count duplicates and use sprintf to append the number onto the string,then fill the remaining duplicates with null values.
In second pass just replace nulls by sweep swapping,this will take O(n^2) in the worst case
Hi monika,
For round2 Q1 does we need to do post & preorder traversal without stack too or for them it is just without recursion?
the approach is same as of interval scheduling
@monika can u give me good link for reading interval schedule problem??
Need this as well.
Please do mail me for
malloc & free implementaion document.
Thanks in advance
typedef unsigned char uint8_t; char * global=<actual memory> typedef struct Block { void *memptr; size_t b_size; /*data hold by this block */ uint8_t is_used; /*either allocated or free */ struct Block *next; /*hold next block */ }block_t; block_t * head = NULL; void malloc(size_t size) { /* check if blocks has enough free space before allocating from fresh chunk*/ block_t *ptr = has_any_block(size); if(ptr != NULL) /* got free block */ { ptr->is_used = TRUE; return ptr->memptr; } else { /* no blocks are free, fresh allocate */ void *tmp_ptr = global; /*allocate mem to holf block */ global = global+sizeof(block_t); /*move global to next free chunk */ block_t *n_block = (block_t *)(tmp_ptr); tmp_ptr = global; /*allocate actual memory */ global = global+size; /*point next free chunk memory */ n_block->memptr= tmp_ptr; n_blcok->is_used= TRUE; n_block->size=size; n_block->next=NULL; add_block_end(n_block); return n_block->memptr; } } void free(void *ptr) { t_block * blk =get_block(ptr); /*find block based on memptr address value */ blk->is_used = FALSE; }Its Microsoft not mircosoft
U are making this spelling mistake too many times!!
check 12 and 13 as well
@Anonyian: Thanks for pointing this out. We have corrected the spelling mistake in all posts. Keep it up!
Hi Monika,
Congratulations to you...Are there openings in Microsoft right now? Also Can u plz mail me that malloc and free implementation tutorial @ manikiscool03@gmail.com.
Thanks in advance
can u plz tell me how to do ques 3 of round 4
thanx in advance
i am really sorry , i want to know ques 4 of round 3
hi monika..
can you please tell...for which comapany you are selected
MS-IT
or
MS-IDC
thnx in advance
MS-IDC
Was it a off campus , if yes, then how?
round 1 ques 3 please ?
Interval scheduling problem
I have got O(n^2) solution. Can you give me solution better than that?
/*its the activity selection problem
arrange the jobs without the smallest finishing time job first*/
i=1;
for(;;)
{
j=i;
while(arr[j+1].sn)
break;
add(j)-->scheduled queue,here arr
}
can any one explain the Round 3 second question
Refer to this link
http://www.geeksforgeeks.org/counting-inversions/
@geeksforgeeks please post a nice article for following
1)
Which data-structure you will use for implementing the ‘malloc’ and ‘free’ functions? (You have been given with a pointer which points to a large chunk of memory).Write full codes for implementing these two functions.
and also how one can design itzz own dynamic memory management
You will find this in KnR "Chapter 8 - The UNIX System Interface".
@aayush: I have a tutorial on maolloc and calloc implementation. If u want, i can mail u that.
Hi,
Thanks for reply.
Please mail me that to aayushkumar08@gmail.com
I will like to read that..:)
I have mailed u the tutorial.
Please do mail me that article as well..
My mail ID is phaneendra.ss@gmail.com
mailed
Please mail me too at anant6926@gmail.com
Can you mail me at guptamurali@gmail.com
mailed u also
Thanks a lot..
I have uploaded the file in the following link.
You can share this following link to all
http://www.yourfilelink.com/get.php?fid=832954
Thanks a lot..
I have uploaded the file in the following link. You can share the following by using the following link..
http://www.yourfilelink.com/get.php?fid=832954
Hello monika,
http://www.yourfilelink.com/get.php?fid=832954
This link is not accessible , could you please provide me with document.
email : atul.87friend@gmail.com
Please mail me doc as well.
plz mail that tutorial at varunv2492@gmail.com
thanx in advance
Please mail the Malloc & Calloc functions implementation
to veeragandham.paparao@gmail.com
any good reference to prepare MCQ questions?
Our new initiative GeeksQuiz can be useful for MCQs.
thanks for sharing. how did u solve the lowest common ancestor problem?
you can see this link for LCA in binary tree:
http://leetcode.com/2011/07/lowest-common-ancestor-of-a-binary-tree-part-ii.html