PAPER: MICROSOFT PLACEMENT PAPER (TECHNICAL)
1. In a X's and 0's game (i.e. TIC TAC TOE) if you write a program for this give a fast way to generate the moves by the computer. I mean this should be the fastest way possible.
ANS:- The answer is that you need to store all possible configurations of the board and the move that is associated with that. Then it boils down to just accessing the right element and getting the corresponding move for it. Do some analysis and do some more optimization in storage since otherwise it becomes infeasible to get the required storage in a DOS machine.
2. I was given two lines of assembly code which found the absolute value of a number stored in two's complement form. I had to recognize what the code was doing. Pretty simple if you know some assembly and some fundas on number representation.
3. Give a fast way to multiply a number by 7.
4. How would go about finding out where to find a book in a library. (You don't know how exactly the books are organized beforehand).
5. Linked list manipulation.
6. Tradeoff between time spent in testing a product and getting into the market first.
7. What to test for given that there isn't enough time to test everything you want to.
8. First some definitions for this problem: a) An ASCII character is one byte long and the most significant bit in the byte is always '0'. b) A Kanji character is two bytes long. The only characteristic of a Kanji character is that in its first byte the most significant bit is '1'. Now you are given an array of a characters (both ASCII and Kanji) and, an index into the array. The index points to the start of some character. Now you need to write a function to do a backspace (i.e. delete the character before the given index).
9. Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]
10. Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.
11. Given an array of integers, find the contiguous sub-array with the largest sum.
ANS. Can be done in O(n) time and O(1) extra space. Scan array from 1 to n. Remember the best sub-array seen so far and the best sub-array ending in i.
12. Given an array of length N containing integers between 1 and N, determine if it contains any duplicates.
ANS. [Is there an O(n) time solution that uses only O(1) extra space and does not destroy the original array?]
13. Sort an array of size n containing integers between 1 and K, given a temporary scratch integer array of size K.
ANS. Compute cumulative counts of integers in the auxiliary array. Now scan the original array, rotating cycles! [Can someone word this more nicely?]
14. 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).
15. 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).