# Microsoft Technical Questions 2015

Posted on :03-02-2016
Q1. An array of size k contains integers between 1 and n. You are given an additional scratch array of size n. Compress the original array by removing duplicates in it. What if k << n?

ANS: Can be done in O(k) time i.e. without initializing the auxiliary array!

Q2. An array of integers. The sum of the array is known not to overflow an integer. Compute the sum. What if we know that integers are in 2s complement form?

ANS: If numbers are in 2s complement, an ordinary looking loop like for(i=total=0;i< n;total+=array[i++]); will do. No need to check for overflows!

Q3. An array of characters. Reverse the order of words in it.

ANS: Write a routine to reverse a character array. Now call it for the given array and for each word in it.

Q4. An array of integers of size n. Generate a random permutation of the array, given a function rand_n() that returns an integer between 1 and n, both inclusive, with equal probability. What is the expected time of your algorithm?

ANS: "Expected time" should ring a bell. To compute a random permutation, use the standard algorithm of scanning array from n down to 1, swapping i-th element with a uniformly random element <= i-th. To compute a uniformly random integer between 1 and k (k < n), call rand_n() repeatedly until it returns a value in the desired range.

Q5. An array of pointers to (very long) strings. Find pointers to the (lexicographically) smallest and largest strings.

ANS:. Scan array in pairs. Remember largest-so-far and smallest-so-far. Compare the larger of the two strings in the current pair with largest-so-far to update it. And the smaller of the current pair with the smallest-so-far to update it. For a total of <= 3n/2 strcmp() calls. Thats also the lower bound.

Q6. Write a program to remove duplicates from a sorted array.

ANS:

int remove_duplicates(int * p, int size)
{
int current, insert = 1;
for (current=1; current < size; current++)
if (p[current] != p[insert-1])
{
p[insert] = p[current];
current++;
insert++;
} else
current++;

return insert;

}

Q7. C++ ( what is virtual function ? what happens if an error occurs in constructor or destructor. Discussion on error handling, templates, unique features of C++. What is different in C++, ( compare with unix).

Q8. Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list).

Q9. Given 3 lines of assembly code : find it is doing. IT was to find absolute value.

Q10. If you are on a boat and you throw out a suitcase, Will the level of water increase.

Q11. Print an integer using only putchar. Try doing it without using extra storage.

Q12. Write C code for (a) deleting an element from a linked list (b) traversing a linked list

Q13. What are various problems unique to distributed databases

Q14. Declare a void pointer ANS. void *ptr;

Q15. Make the pointer aligned to a 4 byte boundary in a efficient manner ANS. Assign the pointer to a long number and the number with 11...1100 add 4 to the number

Q16. What is a far pointer (in DOS)

Q17. What is a balanced tree

Q18. Given a linked list with the following property node2 is left child of node1, if node2 < node1 else, it is the right child.

O P

|

|

O A

|

|

O B

|

|

O C

How do you convert the above linked list to the form without disturbing the property. Write C code for that.

O P

|

|

O B

/

/

/

O ? O ?

Determine where do A and C go

Q19. Describe the file system layout in the UNIX OS

Q20. In UNIX, are the files allocated continuous blocks of data

Q21. How is the fragmented data kept track of Describe the direct blocks and indirect blocks in UNIX file system

Q22. Write an efficient C code for tr program. tr has two command line arguments. They both are strings of same length. tr reads an input file, replaces each character in the first string with the corresponding character in the second string. eg. tr abc xyz replaces all a s by xs, bs by ys and so on.

a) have an array of length 26.
put x in array element corr to a
put y in array element corr to b
put z in array element corr to c
put d in array element corr to d
put e in array element corr to e
and so on.

the code
while (!eof)
{
c = getc();
putc(array[c - a]);
}

Q23. What is disk interleaving

Q24. Why is disk interleaving adopted

Q25. Given a new disk, how do you determine which interleaving is the best a) give 1000 read operations with each kind of interleaving determine the best interleaving from the statistics

Q26. Draw the graph with performance on one axis and n on another, where n in the n in n-way disk interleaving. (a tricky question, should be answered carefully

FreshersLive - No.1 Job site in India. Here you can find latest 2018 government as well as private job recruitment notifications for different posts vacancies in India. Get top company jobs for both fresher and experienced. Job Seekers can get useful interview tips, resume services & interview Question and answer. Practice online test free which is helpful for interview preparation. Register with us to get latest employment news/rojgar samachar notifications. Also get latest free govt and other sarkari naukri job alerts daily through E-mail.

 ✖