You are on page 1of 12

The file contains questions asked by companies in Placements@IITRoorkee, December, 2009.

Interview Questions:

Microsoft
1. Given a function which accepts a character and returns whether a character is escapable or not. Bool IsEscapable(char c); A character is escapable if when preceded by a escape sequence(\) changes the meaning. For example, character n is a normal character, but when preceded by \ it becomes \n which is end of line character. Hence, n is escapable. So are t,r etc. You dont have to worry about whether the character is escapable or not. The given function IsEscapable() returns true if the character is escapable. Now the question is given a string, make a function which for every escapable character in the string, inserts a backslash(\) before it. Sample Input: acndfdtrlp (for characters n,t,r the given function returns true and false otherwise.) Sample Output: ac\ndfd\t\rlp Note: backslash also occupies one character i.e. \n contains 2 characters. Comments: The question was pretty simple and can be done easily but the time complexity has to be good. It can be done in O(n). Still a simple question, way below Microsofts standards. Was also asked to write the test cases. 2. Given two sorted arrays, had to find median of the merged array without actually merging them. Handle all the cases..when u finish writing it, there shouldnt be any case left. What are the test cases that you will form for the program u made. Again simple. 3. How many bytes a character occupies? The trivial answer is 1. But, he wanted me to discuss about Unicode characters which occupies 1-4 bytes depending on format. 4. Given a linked list where each node store characters. Given another linked list representing a substring. Now delete all the occurrences of the substring in the main string. Handle all the cases. Cases: Input:

1. 2. 3. 4. 5. 6.

linked list contains a,b,d,e,f,c,t,d,e,t substring linked list contains d,e Output: a,b,f,c,t,t linked list contains a,a,a,e,f,c,t substring linked list contains a,a Output: e,f,c,t

5. Given a 2-D matrix, write a program print the values of matrix spirally. For matrix: 23457 54261 87360 36226 12345 The output should be: 2,5,8,3,1,2,3,4,5,6,0,1,7,5,4,3,4,7,6,2,2,6,6,2,3 6. How would you develop a program for snake game (the one in nokia mobile) 7. There are 2 linked lists which join at a point, i.e. forms a Y-shape. Find the join pointits a very famous questions, can be found on many sites. 8. Given a complete binary tree, output the coordinates of each node. Example: if the tree in array representation is 2,3,4,5,6,7 the output should be like: 2 (1,10) 3 (2,5) 4 (2,15) 5 (3,2) 6 (3,8) 7 (3,12) i.e. when these points are plotted the nodes form an actual tree structure.

ADOBE
General: The interviewer went very deep into C and C++. The books Test your C skills and Test your C++ skills by Yashwant Kanethkar proved to be extremely helpful. 1. In what cases a constructor is called but a destructor isnt and vice versa.

2. How much memory an empty class occupies and why? (1Byte, to make assignment possible) 3. Why is constructor declared public? Can it be declared as private? What are its advantages. 4. Can a constructor be virtual? Can a destructor be virtual? 5. How much memory a class with a virtual function occupies? 6. How exactly is a virtual table made? Does making the functions virtual have any performance penalty? Design the virtual table for multilevel inheritance. 7. Difference between new operator and operator new. 8. Implement classes in C. Is function overloading possible in C?? 9. Given a Binary Tree how would u find if it is really a BST?? 10. How would you do a linear search efficiently? Normally, for every iteration we do 2 comparisons as illustrated below: For(int i=0;i<n;i++) if(a[i]==item) return i; Improve the code so that u need to do just one comparison in every iteration. (Hint: assume that u have an array of length n+1 with space for one element.) 11. Divide a square into 4 congruent parts. (infinite solutions possible) 12. How does an airplane fly? How does GPS works? 13. Differences between private inheritance and declaring a pointer of a (supposedly base)class in private of (derived)class. (think about data structures) 14. There are 6 balls, 2 each of color green, blue and yellow. 1 ball of each color is heavier than the other. In two weighings find the 3 heavy balls. (the 3 heavy balls weigh the same and so do the 3 light balls) 15. How many 0s are there in 100! ? 16. How are threads and virtual memory related. Effects of threading on virtual memory.

Questions asked in written test: Microsoft Find the middle of a linked list in a single iteration. Find the ancestor of 2 given nodes in a BST. Copy <des> <src> Write 10 test cases. Draw a paint application for kidsyeah u read it right.

1. 2. 3. 4.

Adobe 2 papers (Each paper contained 10 ques, time allotted 45 mints for each) Paper1: C 1. Find the size of the given union data structure. (obv the size would be the maximum of the size of individual elements as they all share common memory) 2. Differentiate between calloc and malloc. 3. Write A Program(WAP) to swap 2integer pointers. I made a conceptual mistake. (Hint: In formal parameters receive double pointer(int **). 4. Given a string and a substring. Find the no of occurrences of the substring in the given string. 5. Given 2 unsigned integers, WAP to find if their sum exceeds the integer limit ( 232 ). 6. A question on finding the output which u can do correctly only if u know the order of expression evaluation in printf(). (it is from right to left) If a=5; Printf(%d%d,a++,++a) will print 6 6 and not 5 7. 7. Given an array of n integers containing nos from 1to n-1 with one number repeated. Find the repeated number(very common question) 8. WAP to print all the permutations of a given string. 9. WAP to reverse a string without using any other data structure. 10. WAP to invert odd bits of a number (hint: use xor).

Paper 2: DS and others 1. A question on making a DFA (easy one) 2. WAP in assembly language to find sum of numbers from 1 to n. Instructions allowed: LDA n //load n in accumulator(A) MOV R1,R2 //move content of register R2 to R1 INR //increment content of accumulator(register A) DCR //Decrement content of accumulator JZ label //jump to label if accumulator is 0 JNZ label //jump to label if accumulator is not zero Given 3 registers A(accumulator),B and C. The final sum should be stored in B. 3. An array contains only 0s and 1s. Sort the array in O(n). 4. A puzzle. The diagram cant be drawn.

Amazon
*Round1* Q1) You are required to create a data structure which will allow the following operations in O(1) time. Assume the data structure can have only elements with value 1 to 1000 (all distinct). a)Insertion b)Deletion c)Searching d) Return Any Valid element (that is an element which is there) Eg Insert(3); Insert(5); Insert(6); Insert(2); Delete(5); Valid(); // can return 2 or 3 or 6 Q2) Write a complete program (handle all cases) that deletes an element from a doubly linked list. It takes the head pointer and value of the element to be deleted. Assume all values distinct. Q3) What is the data structure that you would use for the auto complete feature. Suppose you google search "cat", "catalyst", "elephant", etc..... , so when you later write "cat", it should automatically suggest "cat", "catalyst",... etc. That means all previous search queries that are prefixed with "cat". *Round2* Q1) Knapsack problem, given utility per unit weight, max weights of each item and total weight allowed. Then a minor modification of including prices per unit weight also. So solve this minor changed problem by maximizing utility and minimizing price. Further reduce the number of sort operations. Q2) A problem on dynamic program. There are several cities in a straight line. There is a starting city and an ending city. Distances of cities from the start city are given in an array. A traveler can travel only N kilometers in a day, and must stay the night in a city. There is a toll for each city which the traveler pays if he is NOT staying the night (it could be more than, less than or equal to the per night cost of hotel at that city). Develop an algorithm to find minimum cost for the person to travel from start to end and then code it! Do not use recursion / stack in the code. However can use array.

*Round3* One question particularly was carried forward and built into a function which I had to further optimize. Actually he hadn't come prepared with what questions to ask, but when I said that search trees is one example of a data structure that I am aware of then he decided to test my knowledge on that. Function input -> Number of elements in the search tree. Function output -> Number of ways that the search tree can be generated.

Other Questions asked in Amazon:


--> binary tree clone --> power set of a given set --> deleting all occurrences of a number from a doubly linked list --> for chess game design class hierarchy --> inter process communication ( which is better etc.) --> what variables/register values are pushed on stack when a function is called. --> how to find stack is growing upward or backward in a machine. --> different segments in a process address space. --> (puzzle) you have to take total n step and you can take 1 or 2 steps how many paths possible. -->(puzzle) a N x N matrix having only 0 and 1 and all rows are sorted find the row with max 0 in O(n) time. --> (puzzle) total n players...each play a match with all other players...is there a way to arrange all players in a array such that for a player at ith position, he has defeated player at position i-1 and has been defeated by player at position i+1. if yes....then prove it. -> find subtree with max cummulative weight ( where cumm weight=weight of root+ wt of left subtree+wt of right subtree)

--> one SQL query ( which i don't think anyone has attempted )

Yahoo
My Resume was minimalist. Always keep it that way. It gives a good impression. You winning the 3rd prize in an intra-bhawan painting competition is not going to capture their attention. My CG was not high, but I compensated a lot by my other projects and extra-curriculars. And by extra-curriculars, most of them were coding/open source activities (I was in IMG), which I believe was helpful. The Interview was simple, only for about 10 minutes. By this, they were just checking if the person really answered the questions by himself and was not just randomly marking the answers to the questions in the initial multiple-choice no-negative-marking written test. This was then followed by very simple questions (all types of sorting, etc). I was lucky since my interviewer(only 1 person) was higher up in the management and was not abreast with high-level CS interview questions that were being asked by other companies. He had a very good look at my resume then, and most of the questions were based on it. My coding contributions to opensource, dual degree Thesis topic on Semantic Web, GSoC, were all inquired about and (possibly) did have some effect. How did they reject people on basis of the interview? Frankly, I don't know. Written Test -> Interview -> Programming Test. This was the whole selection procedure. While the first 2 parts of the procedure redefined the whole definition of "easy" :), the final programming test more than compensated for the apparent "easy to crack" exterior of Yahoo!. In 3 hours, the problem was to code (entire!) DBMS in a programming language of your choice. I was more adept with Java than with anything else, but the Institute CC forced me to use my archaic C++ skills. Searching the internet was allowed, but then obviously we were being moderated at all times. I spent the first 10 minutes thinking about how to approach the problem, and recollecting my C++ knowledge. If you know me personally, then you'd know that I very much hate the pointers concept or its use, but then again, by the end of 3 hours, I had almost mastered its usage! Obviously everyone had his/her way of solving the problem... But here, I list the points of what I did right: 1) I knew that the most efficient representation of DBMS was B+ trees, since most DB's used it them (read it somewhere). But then, creating a B+ tree was not possible/feasible. I needed an alternative solution. 2) I was in touch with the moderators quite often, letting them know of my thought process and reassuring with them the way I was went on with was correct. 3) I started from the most basic of data structures, the linked list representation of rows as records, and worked my way up. This helped a lot. I used to code fast and test often within every short intervals (this was especially useful since I had to check if all my pointers were working nicely.. and helped me avoid that god_knows_where_i_went_wrong kind of segmentation faults at the end).

4) My solution implemented all the features they asked for (5 different sql-typed queries) and its efficiency was O(n) which was just ok. I explained myself of how I would improve upon it given more time (indexed hashing etc..). Though I didn't know at the time of coding, I later found out from peers that I had implemented the max no. of features (Big +ve point). 5) My solution was very dynamic, i.e , It could support any number of fields (either integers or strings) and could have any number of tables, rows, etc. This was another plus point. CG does not matter for Yahoo as long as it is > 7. For Microsoft and Adobe however, that's another thing.

NetApp
-> What is Signal n how they r used in OS? -> Forking of Processes -> int i=10, Char *c=i, print c ... how does it work? -> Program for Binary Search in Array...with error conditions. -> What is a Memory Leak? Give Example ->What is a Dangling Pointer? How can these be Avoided?? -> How does malloc( ) work?? -> Program for your own myprintf( ) function! -> int *i =malloc() ... free(i);... *i=10; what happens?? Ans:- Segmentation Fault(Define) -> Program to search a given string in a longer string starting at the end of longer string i.e., Implement ur own subrstr() function -> Puzzle :- 25 Horses were there... A race can b Arranged for 5 horses only at a time.. How many min no. of races required to find the first 3 Fastest Horses.... Ans:- 8 Races... 5 Individual Races + 1 race btwn winners gives FAstest Horse... n Take 2nd horse in Winners Race and arrange Race wid 2nd Positions in other Races to get 2nd fastest...same for 3rd fastest = 8 Races -> Puzzle :- A Bridge can carry only 2 persons at a time.. A,B,C,D need to Cross the Bridge at Night.. A takes 1min, B Takes 2mins, c takes 5Mins, D takes 10Mins to Cross the Bridge...They Need Torch to Cross which can last only 18Mins.... How does all 4 Cross the Bridge b4 torch gets Discharged????

-> Also asked questions on system software.

DE Shaw (Telephonic)
-> Puzzle :- 3 Ants are at the Corner of a Triangle.. They Move along the Sides of the Triangle...Wat is the Probability that they dont collide Ans:- 0.25.. Coz each ant can move in two directions => 2*3 =8 ways... Inorder not to collide..All shud move either clockwise or AntiClockwise=>2 Favourable ways... Prob= 2/8 =0.25 -> Puzzle :- Divide a Triangle into 5 Equal Parts -> Puzzle :- u have 20 x 10 ChessBoard... How to Find the no of Rectangles in it?? -> How to Find a Loop in Linked List? -> Differnce btwn Interface n Abstrct class in Java? -> Garbage Collection in Java -> How Polymorphism is possible in Java which doesnt support Pointers... -> Y java doesnt Suport Multiple Inheritance? -> In a Linked List each Node has 1extra pointer which points to a random node in the List. How to Create a Copy of this Linked List? -> Lots of Qs on Project -> U have Infinite No of Points on a Plane... How to Find the Largest Regular Polygon out of those (Polygon wid Obtuse Interior Angles) -> Puzzle:- u have a Stick which can b Broken into 3 Pieces.. Wat is the Prob that these pieces form a Triangle? Ans:- 0.33 Hint(In Triangle, sum of 2sides is greater dan the third side) -> abt DataBases ( I said im nt acquanted wid DBMS) -> Algorithms to Find the Shortest Path in A graph -> Where do u use graph Theory n wat r its applications?? y is it prefered?? -> Which version of JVM do u use?

Oracle Server Technologies


Puzzle:- He gave a Bus with windows n widout Doors.... Everything is Symmetrical in the Figure...He asked me in which direction the Bus is Moving.(Hint:- Its Indian Bus) Ans:- Doors on other side, so bus wud move to right as people board frm other side -> what is SDLC? (Software Development Life Cycle) n explain steps involved in it -> how does a Program execute?? Steps ( compiling, loading, executing in detail) Refer Galvin -> Write a Program to Print the last n Lines in a File -> About Project in Detail -> how do u implement C++ class functionality (private,public,protected, funtions etc) in C's Structure?? -> Difference btwn fopen n open? Y fopen is library func n y open is system call?? How does OS ensures the non violation of Permissions on files -> Write a prgm to print last n lines of the file widout using Fast Slow pointer Method. -> Forking Processes etc -> Give a Practical Example for DeadLock (Bankers Algo) -> Write a Program to Implement a DeadLock

nVidia Graphics
-> Steps in Program Execution ...compiling linking loading etc again -> Program to print the no. of bits set in the number -> OS concepts on Threads, Processes, Memory Management -> Difference btwn Binary Semaphore n Mutex ->What r the Differnt Synchronization tools available? -> Loop in Linked list -> program to insert word "nVidia" at last 6 letters of a given String. -> Puzzle :- 100 Doors... Initially closed... etc.. Search 100 doors in google.. u vl directly get prob n answer. Write a Program for the Same; Give Mathematical Interpretation of the Same

-> Devise a Currency Note System such that if i ask any amount... U shud b able to give it in sum of only 1 note of each Notetype dat is if 20 asked -> 1 20's note but not 2 10's notes shud b given. Ans:- Use Binary... 1 2 4 8 16 32 64 -> 7 Notes requred...Given any no..convert it into Binary n give those notes which have 1's in Binary found

Fiorano Software Technologies


Gud Company and they concentrate more on Complexities of Algorithms.... -> Difference btwn Java's Interfaces and Abstract clases -> Program Execution Steps again -> difference btwn static and extern -> How do u find the comon elements in 2 unsorted arrays?? complexity For every step they askd me

-> Which is Faster? PostOrder/Preorder/Inorder?? Ans:- All same...as code is same...Position of Printf makes no differnce -> Explain how the complexity of Merge sort is 0(nlogn) -> c program to print the reverse of the string -> c program to print all substrings of a given string -> int *i; while(1) { i=(int *)malloc(sizeof(int)); } ....What will be the Output??

Informatica
Round 1:-> How does Fork() work? How does shell work?? wats exec() does?? -> Find the Comon elements in 2 unsorted arrays.... ans:- BruteForce -0(n^2) -> Constrct BST of 1array n search elemtns of 2nd array in it 0(nlogn) Worst Case:- 0(n^2). ->Sort one array and Do Binary search of 2nd array elemnts in this Sorted 1st array 0(nlogn) again. ->Constrct Hash Table of 1 array and search for 2nd array elements as keys...Only 2nd aray need2b traversed 0(n) --> Most Efficient

-> Write a program for Binary Search in array... -> Write a program which finds the count of no of Repetitions of a given key value in the Array (with repetiotions ofcourse) Ans:- Use Binary Search and Count the Occurences... -> Write a program which Returns the First occurance of a gvien key in a array which allows repetition (Use Binary search again) -> When a Process Forks...wat all r shared among parent n child processes?? -> Will the Threads in the Parent Process get copied into Child Process?? -> Asked about my PRoject and Dissertation Round 2:->He Went thru my resume for 15 Minutes asking. He askd abt my +2 percntage -> Write a program using Atomic signals like Wait n Signal to Implement a class of LOcks with Compatibility constraints. (R-R is only allowd) if a proces has write lock...other processes shud wait... if a proces holds read locks..other processes can acess the code . -> Luckily Same Question again as was in 1st Round.... Common elements in 2 arrays.... He gave two Tables with Indexes...and asked to do Join operation on Indexes (finding common elements only if u observe) again Same answers... worked out pretty well ! -> den he askd abt my Hobbies... I said Playing Cricket....He askd whethr i follow cricket also... I said I used to in my BE bt nw in IIT im nt getting time..... I said Right Now also Im very Busy in my Dessertation work.... He was again impresed and shifted to my desertation topic and askd me to xplain Compiled by Vineet Kumar Chirania (CS-IDD, Batch of 2010, Placed in JP Morgan Chase). With inputs from: Vickramaditya Dhawal (Placed in Adobe) Saurabh Sharma(Placed in Amazon) Venkatesh N (Placed in Yahoo!) Naga Sathish Gidijala (Placed in Informatica)

You might also like