Freshers InterviewsTechnical & HR Interview Questions of Google,Microsoft,Yahoo and many more Companies.noreply@blogger.com (chaitanya)Fri, 2 Dec 2022 19:54:35 +0530Blogger http://www.blogger.com300125http://placementsindia.blogspot.com/en-usnoPlacement Papers of 220+ Companies,Technical Interview,Hr Interview Tips,Group Discussion Topics and answers,How to Prepare a Professional Resume,Get Off campus details and Get Most Commonly Asking Puzzles with solutions.Freshers Placementskchaitanyya@gmail.comCitrix Written Test Questions-1http://placementsindia.blogspot.com/2008/01/citrix-interview-questions-1.htmlInterviewsTue, 4 Nov 2008 19:14:00 +0530tag:blogger.com,1999:blog-32064785.post-29625320093217048361. What is the output of this statement ?<br />Printf(“%d”,printf(“%d %d”,2,2) & printf(“%d %d ”, 2, 2));<br />a. 22222 <br />b. 22221<br />c. It will give an error during compilation<br /><br />2. What is the output of this code snippet<br /><pre><br />main()<br />{ int *p[10];<br /> printf("%d %d\n",sizeof(*p),sizeof(p));<br /> }<br /> </pre><br />3. Function inlining is best used when <br />a. In a small recursive function <br />b. In large function where number of variables used is small<br />c. In a large function where there are many loops and number of variables used is small<br />d. None of these<br /><br />4. If there is a large quantum in round robin it will be equivalent to <br />a. First come first serve <br />b. Shortest job first<br />c. Least recently used<br />d. None of these<br /><br />5 . which of the following will lead to starvation<br />a. Fifo <br />b. Shortest job first <br />c. Round robin<br />d. Least recently used<br /><br />6 . if the address space is 192.168.36.16/28 which of the following is the broadcast ip<br />a. 192.168.36.0<br />b. 192.168.36.1<br />c. 192.168.36.255<br />d. 192.168.36.31<br /><br />7. if there are 9 yellow balls, 3 red balls and 2 green balls. What is the probability that the second ball picked is yellow given the first ball is yellow<br /> a. 8/13<br /> b. 9/13<br /> c. 8/14<br /> d. 9/14<br /><br />8. How many processes are created in this snippet?<br /> Main()<br /> {<br /> Fork();<br /> Fork() && fork () || fork ();<br /> Fork ();<br />}<br /><br />a. 15<br />b. 19 <br />c. 21<br />d. 27<br />e. 31<br /><br />9. which of the following is TRUE about the declaration const char * p <br /> a. the pointer cannot be changed but the value to which it points can be changed<br /> b. the value is constant but the pointer can be changed<br /> c. neither the value nor the pointer can be changed<br /> d. none of these<br /><br />10. If F and L are the pointers to the first and last elements in a linked list, then which of the following operations is dependent on the length of the list?<br /> a. delete the first element in the list<br /> b. insert a new element as a first element<br /> c. delete the last element of the list <br /> d. add a new element at the end of the list441kchaitanyya@gmail.com (Unknown)Citrix Written Test Questions-2http://placementsindia.blogspot.com/2008/01/citrix-interview-questions-2.htmlInterviewsSun, 26 Oct 2008 19:25:00 +0530tag:blogger.com,1999:blog-32064785.post-831294358470464692111. Find the slope of the line joining the points (0,2) and (3, -2)<br /> a. -4/3 <br /> b. ¾<br /> c. -3/4<br /> d. 4/3<br /><br />12. Solve for x in x^3+3x^2+5x+9=6<br /> a. -1<br /> b. 1<br /> c. -2 <br /> d. -3<br /><br />13. 73 to the base x is equivalent to 51 to the base y. which of the following may be the possible values of x and y<br /> a. 10, 12<br /> b. 8, 16<br /> c. 9, 13<br /> d. 8, 12<br /><br />14. Which of the following is independent of the operating system and machine architecture<br /> a. linker<br /> b. loader<br /> c. compiler<br /> d. debugger<br /><br />15. Which of the following restricts a process to the memory allocated to it<br /> a. stack pointers<br /> b. memory allocation hardware<br /> c. kernel<br /> d. none of these<br /><br />16. When a user logs out, what happens to the processes created by him?<br /> a. they’ll be killed<br /> b. aborted<br /> c. hang<br /> d. none of these<br /><br />17. What is the output of<br />Main()<br />{<br /> Struct node {<br /> Int a;<br /> Int b;<br /> Int c;<br />};<br />Struct node a = {2,4,5};<br />Struct node *st;<br />St = &a;<br />Printf(“%d”, *(int *)st);<br />}<br />a. 2 <br />b. 3<br />c. 7<br />d. 11<br /><br />18. What is the output of <br />Struct outer{<br /> Struct inner{<br /> Int a = 10;<br />}<br />Int b = 5;<br />}<br />Main()<br />{<br /> Struct inner new;<br /> Printf(“%d”, new.a)<br />}<br />a. It will give a compilation error <br />b. 10<br />c. 5 <br />d. 15<br /><br />19. Thrashing is solved by <br /> a. increasing cpu bound processes <br /> b. reducing the degree of multi-programming<br /> c. increasing user processes<br /> d. none of these<br /><br />20. If t` is the reverse of t then what is the reverse of trs<br /> a. s’r’t’<br /> b. srt<br /> c. t’r’s’<br /> d. t’rs’5kchaitanyya@gmail.com (Unknown)Cisco Interview Questionshttp://placementsindia.blogspot.com/2008/01/cisco-interview-questions.htmlCiscoInterviewsTue, 21 Oct 2008 13:24:00 +0530tag:blogger.com,1999:blog-32064785.post-66106048624443477951)Explain an algorithm for path planning in a given map.<br /><br />2)Write a code to find the shortest path in a given graph.<br /><br />3)Write a code for minimal spanning tree <br /><br />4)How do you find existence of a cycle in the given graph.<br /><br />5)Explain OSI model. <br /><br />6)How do you find out the sizeof an object in Java.<br /><br />7)Given a byte, write a code to swap every two bits. [Using bit operators] Eg: Input: 10 01 11 01 Output: 01 10 11 10<br /><br />8)Write a Shell code which takes in as input several files and replaces each occurance of word “Nishant” with word “reddy”.<br /><br />9)What is VPN ?<br /><br />10)What are TCP/IP protocol , Routing algorithms , P2P file sharing , Routing protocols.<br /><br />11)Implement the above protocols in C.7kchaitanyya@gmail.com (Unknown)Cisco HR Interview Questionshttp://placementsindia.blogspot.com/2008/01/cisco-hr-interview-questions.htmlCiscoHR InterviewsThu, 16 Oct 2008 13:30:00 +0530tag:blogger.com,1999:blog-32064785.post-72321106128562927341)What are the names of your technical round interviewers <br /><br />2)Do you know my name ?<br /><br />3)Tell me about yourself, your family background... so on..<br /><br />4)What are you looking for in Cisco” or what attracts you or why do you want to join cisco. <br /><br />5)Tell me a situation/ issue where you identified a problem on your own, and drove to resolve it. <br /><br />6)Tell about most difficult team project u have worked on. <br /><br />7)What type of work environment is suitable and which environment you hate/is frustrating?<br /><br />8)Tell about the mistake you learned from<br /><br />9)Tell about accomplishment you are proud of...<br /><br />10)what have you learnt in 4 years of your BTech.<br /><br />11)Give an example of biggest/most demanding team leading or you have talked about some thing to a group like given a presentation or seminar etc..<br /><br />12)Describe a situation where you and your partner/professor had a conflicting view, but you were still able to get across your point or how did u get around obstacles that prevented you from completing the task/project.<br /><br />13)Tell a situation in which you took the lead without being asked to do so and why? or you saw some opportunity which came suddenly and how did u react? or you found some your results or your work which were not up to the mark, what did u do to rectify? or done more than what was required? or situations in which you found the job could be done much easier and others weren’t following it..? or did some job which doesnt come under your job role/description but was beneficial?<br /><br />14)Tell me about your values in your life.<br /><br />15)Tell us what do you know about our company.<br /><br />16)Tell me some of your strengths and weaknesses.. <br /><br />17)Interested in doing MS ?5kchaitanyya@gmail.com (Unknown)CapitalIQ Interview questionshttp://placementsindia.blogspot.com/2008/01/capitaliq-interview-questions.htmlInterviewsSun, 12 Oct 2008 18:33:00 +0530tag:blogger.com,1999:blog-32064785.post-14244833133839533921. How are databases stored internally ?<br /><br />2. Can you think of any improvements to the storage of databases<br /><br />3. What is indexing in databases and how does it help ?<br /><br />4. Differences between search engine index and database index ?<br /><br />5. What is paging in operating system ?<br /><br />6. Explain the difference in different types of pagings in different situations – Constraints on the implementation<br /><br />7. How can you implement paging in databases ?<br /><br />8. What happens when you search for a value in a database ?<br /><br />9. What are the different types of cache available .. explained about L1 L2 and onchip offchip caches and their access times and cost<br /><br />10. What is an RDBMS ? What are the differences or relation between RDBMS and DBMS ?<br /><br />11. What are the different types of joins in a database. Explained every join[Natural,Inner outer etc ., ] with examples.7kchaitanyya@gmail.com (Unknown)CapitalIQ HR Interview Questionshttp://placementsindia.blogspot.com/2008/01/capitaliq-hr-interview-questions.htmlHR InterviewsTue, 7 Oct 2008 11:28:00 +0530tag:blogger.com,1999:blog-32064785.post-77540539125421906981.General introduction stuff.<br /><br />2.Why capitalIQ ?<br /><br />3.What are the different challenges faced in general?<br /><br />4. What challenges did you face?<br /><br />5. What would you do if you were given 10 lakhs.<br /><br />6. What are your Past time activities.<br /><br />Director Round<br /><br />1. Explained about his company and work and the asked me to explain how I am a suitable candidate for the job.8kchaitanyya@gmail.com (Unknown)Infosys Setlabs Campus Interviewhttp://placementsindia.blogspot.com/2008/01/infosys-setlabs-campus-interview.htmlInterviewsFri, 3 Oct 2008 10:41:00 +0530tag:blogger.com,1999:blog-32064785.post-3636845728420273120Written test was on aptitude and verbal. Its was more like a cat paper. <br /><br />There was one round of interview (kinda stress mostly on the projects). <br /><br />Questions: <br /><br />1) Tell me about yourself <br />2) Tell me the projects you worked on <br />3) Which project did you like the most and why ? He will ask you questions about your projects, why did you do this why not in this way … <br />4) Ur future plans. <br />5) Why Setlabs ?2kchaitanyya@gmail.com (Unknown)ADP Campus Interviewhttp://placementsindia.blogspot.com/2008/01/adp-campus-interview.htmlInterviewsFri, 26 Sep 2008 10:45:00 +0530tag:blogger.com,1999:blog-32064785.post-4059139719940519623<b>Technical Interview</b><br /><br />1) What are the ways of representing floating point nos?<br /><br />2) What are various Datatypes?<br /><br />3) Write the code for tic-tac-toe game, 8 queens problem.<br /><br />4) Write the psuedo code for towers of hanoi and what if there were 4 towers instead of 3.<br /><br /><b>HR Interview</b><br /><br />1) What do you know about ADP? <br /><br />2) What is your dream company? and Why?<br /><br />3) How did you come to know about ADP? If you heard about this from your seniors, who are they and what did they tell you?<br /><br />4) And some common questions like Tell about yourself, Family Background etc.. and also the interviewer asks if you have any questions for him.3kchaitanyya@gmail.com (Unknown)Fractural Analysis Latest Placements Interviewhttp://placementsindia.blogspot.com/2008/02/fractural-analysis-latest-placements.htmlMon, 22 Sep 2008 09:27:00 +0530tag:blogger.com,1999:blog-32064785.post-4206512643771543167<a href=http://placementsindia.blogspot.com/2008/02/fractural-analysis-latest-placements.html><b>Written test</b></a><br /><br />In the written test few questions were asked based on the english and general knowledge and math aptitude.<br /><br /><a href=http://placementsindia.blogspot.com/2008/02/fractural-analysis-latest-placements.html><b>Technical Interview</b></a><br /><br />1. This interview was purely based on nlp and knowledge in information retrieval areas.<br /><br />2. Algorithm to implement IR systems using semantics. Example: If a user gives a query “book-review”. We need to retrieve web-pages that are really book-reviews of some other pages but not those web pages which contains the word book review.<br /><br />3. A scenario was given like this and i was to implement a search system. In that interview he gave me “food scenario”. If u r building a search engine what r things u will do. (We need to explain from initial steps such as raw data collection and structure data storage until search algorithm)…. These questions purely based on IEIR - NLP.<br /><br />4. If u r building a search engine what r all the problems u will face as a programmer (plan-design).<br /><br />5. Will u be fit for this company. so be aware of job profile carefully what r the things u know about work in fractal?<br /><br />6. In language translation questions regarding Machine-Translation systems /Rule based systems were asked ?2kchaitanyya@gmail.com (Unknown)Ikoa semiconductors Interview-1http://placementsindia.blogspot.com/2008/09/ikoa-semiconductors-interview-1.htmlFri, 19 Sep 2008 18:41:00 +0530tag:blogger.com,1999:blog-32064785.post-66536609655140946281st round : Aptitude (written test) - 30 min<br /><br />There were total 30 Multiple Choice questions. 2 for correct and -1 for wrong, pretty simple questions… doing PPTP questions would be more then enough for it.<br /><br />(Tips :- Don't attempt the question if you are not sure of the answer)<br /><br />2nd round : Technical (written test) - 60 min<br /><br />It was a descriptive paper, there were 12 questions covering topics from C/C++, Digital Logic Design, Computer Organization, Microprocessors (they were in impression that we have been taught C++ here)<br /><br />1. Define a structure class in C++.<br /><br />2. one question based on OOPS.<br /><br />3. A circuit diagram using CMOS was given and we were asked to find the logic expression.<br /><br />4. Three questions on State Diagram.<br /><br />5. Some questions on solving logic expressions<br /><br />6. write a C code for strlen().<br /><br />7. question on memory - like build a 2M X 32 memory using 64K X 8 memory cell.<br /><br />(Tips :- Try to attempt all the questions, since no negative marking and draw digram where ever possible, it add to the examiners comfort when they check the paper)1kchaitanyya@gmail.com (Unknown)Ikoa semiconductors Interview-1http://placementsindia.blogspot.com/2008/02/ikoa-semiconductors-interview-1.htmlTue, 16 Sep 2008 18:41:00 +0530tag:blogger.com,1999:blog-32064785.post-54409955872298409181st round : Aptitude (written test) - 30 min<br /><br />There were total 30 Multiple Choice questions. 2 for correct and -1 for wrong, pretty simple questions… doing PPTP questions would be more then enough for it.<br /><br />(Tips :- Don't attempt the question if you are not sure of the answer)<br /><br />2nd round : Technical (written test) - 60 min<br /><br />It was a descriptive paper, there were 12 questions covering topics from C/C++, Digital Logic Design, Computer Organization, Microprocessors (they were in impression that we have been taught C++ here)<br /><br />1. Define a structure class in C++.<br /><br />2. one question based on OOPS.<br /><br />3. A circuit diagram using CMOS was given and we were asked to find the logic expression.<br /><br />4. Three questions on State Diagram.<br /><br />5. Some questions on solving logic expressions<br /><br />6. write a C code for strlen().<br /><br />7. question on memory - like build a 2M X 32 memory using 64K X 8 memory cell.<br /><br />(Tips :- Try to attempt all the questions, since no negative marking and draw digram where ever possible, it add to the examiners comfort when they check the paper)2kchaitanyya@gmail.com (Unknown)Latest MicroSoft Interview Questionshttp://placementsindia.blogspot.com/2008/09/latest-microsoft-interview-questions.htmlMicrosoftSat, 13 Sep 2008 19:52:00 +0530tag:blogger.com,1999:blog-32064785.post-49216252498206349681)Given a Parent -Child binary tree ,build the child -sibling version of it?<br /> Minimize the space requirements wherever possible.<br /><br />2)Given a binary tree build a linked list of all its nodes such that the nodes of a level appear before the nodes of the next level?<br /><br />3)Given an infinite stream of bits with the bits being appended at the highest significant position. give an algorithm to to say whether the number formed by using the sequence of bits that had been processed till then, is divisible by 3 or not?<br /><br />4)Given a string S of words and no of character per line m ,with m being greater than the longest word in S,print S in a set of lines so that each line contains no more than m characters and no word split between 2 lines.<br /><br />5)Given an expression remove the unnecessary brackets in it with out creating an ambiguity in its execution.<br /> input output<br />ex1: (a+(b)+c) a+b+c<br /><br /><br />ex2: (a*b)+c a*b+c<br /><br /><br />6)Propose a tree based data structure to identify a node with nth rank with maximum efficiency .<br /><br />7)Given a string S of alphabets and 2 characters a,b find the minimum distance between instances of them such that position of a <= position of b.<br /><br />8)Given an array of size n with first l positions filled with characters and a string s ,replace all the instances of ’%’ with this string s,given that the lengh of the array is sufficient to handle these substitutions.<br /><p> input output<br /></p><p>eg: abcdef%ghi%—— and “ppp” abcdefpppghippp</p><br /><p>9)Given a binary tree verify whether it is a binary search tree or not?</p>10)Write a C code to merge 2 binary search trees and do the same 2 merge linked lists.How is the former different when compared to the later.(Discuss the issues)<br /><br /><br /><p><br /></p><p><br /></p><p><br /></p>2kchaitanyya@gmail.com (Unknown)Yahoo Interview Questions-2http://placementsindia.blogspot.com/2007/12/yahoo-interview-questions-2.htmlInterviewsyahooThu, 3 Jul 2008 11:38:00 +0530tag:blogger.com,1999:blog-32064785.post-870669428214528385<ol><br /><br /><li>Design a data structure such that given a stream of numbers, you can find the maximum of the numbers at any point and also all the numbers.</li><br /><br /><li>Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions.</li><br /><li>Find the common ancestor of two given nodes in a binary tree, how do you exploit the properties of a given BST for the same problem.</li><br /><li>Given a function getsort(data),that sorts the data given. The function sorts in place and does not use any extra memory. How do you validate the function with respect to 1)it sorts 2) it does not use extra memory</li><br /><li>Explain the Traveling Salesman problem? What is an NP-complete problem? What is the Hamiltonian cycle problem?</li><br /><li>Find out the least common ancestor in a binary tree.</li><br /></ol>3kchaitanyya@gmail.com (Unknown)Yahoo Interview Questions-1http://placementsindia.blogspot.com/2007/12/yahoo-interview-questions-1.htmlInterviewsyahooSun, 29 Jun 2008 11:34:00 +0530tag:blogger.com,1999:blog-32064785.post-605961379307681403<ol><br /><li>A modified insertion sort uses binary search to find the position of insertion. What would be the improvement in order realized?<br /></li><br /><li>class a{};<br />main()<br />{<br />count <<><br />}<br />What is the output?<br /></li><br /><li>The linked list size is unknown and it is very large. Find out the N th element from the back end.<br /></li><br /><li>What happens in the following code?<br />char x[10],y[10];<br />x=y;<br /></li><br /><li>Design a stack which supports push, pop, min and max operations in O(1).<br /></li><br /><li>Design an NFA to accept a string of 0s and 1s.<br /></li><br /><li>Given a balanced BST tree, write a function to replace the root with a node that belongs to the original tree.<br /></li><br /><li>Explain what this function does<br /><pre><br />char *mystrcpy(char *s)<br />{<br />char des=char [MAXLEN];<br />char * t=des;<br />while(*s)<br />{<br />*++t=*++s;<br />}<br />return t;<br />}<br /></pre><br /></li><br /><li>Given that you have a server hit by around 400 million users, and you have log files that contain the user ids of all of them. How do you find the frequency of login of each user. (The log files are very huge!!)<br /></li><br /><li>Explain Polymorphism, Encapsulation, Inheritance, operator overloading?<br /></li><br /></ol>1kchaitanyya@gmail.com (Unknown)Latest DE Shaw Interview Questionshttp://placementsindia.blogspot.com/2007/12/de-shaw-interview-questions-2.htmlInterviewsFri, 27 Jun 2008 08:37:00 +0530tag:blogger.com,1999:blog-32064785.post-5559993525368056193<span style="font-weight:bold;">Question1</span>: Differentiate HTTP and HTTPS <br /><br /><span style="font-weight:bold;">Question2</span>: Discuss ACID properties of a database system.<br /><br /><span style="font-weight:bold;">Question3</span>: Given a table Employee with only one field: Names, report all names with multiple entries.<br /><br /><span style="font-weight:bold;">Question4</span>:Given two sequences s1,s2 and another sequence s3, find if s3 is formed by interleaving s1 and s2.[Example: s1:abcd s2:bcaa s3:abbccdaa].<br /><br /><span style="font-weight:bold;">Question5</span>: If a class B is inherited from a class A, B has a function foo which is also in A, how do you call foo function in A??<br /><br /><span style="font-weight:bold;">Question6</span>: If a class B is inherited public from a class A, what all the variables that can be accesses and those that cannot be.<br /><br /><span style="font-weight:bold;">Question7</span>: List out the additional features of C++ over C when the latter is already available as a good programming language?<br /><br /><span style="font-weight:bold;">Question8</span>: Can classes,protected variables or other features in C++ be implemented using C?<br /><br /><span style="font-weight:bold;">Question9</span>: Define Deadlock<br /><br /><span style="font-weight:bold;">Question20</span>:Given a multi-threaded program How can you make it run on a system that supports only a single thread execution? <br /><br /><span style="font-weight:bold;">Question11</span>:What are the Differences between a const char * and char const *?<br /><br /><span style="font-weight:bold;">Question12</span>:What are the Differences between a reference variable and pointer variable in C++?<br /><br /><span style="font-weight:bold;">Question13</span>What is a register variable and what are the limitations on it? What is an automatic variable?<br /><br /><span style="font-weight:bold;">Question14</span>What are the Differences in memory allocation in array and pointer(stack and heap)?<br /><br /><span style="font-weight:bold;">Question15</span>Find the missing element in a sorted array in most optimum running time (O(log n))2kchaitanyya@gmail.com (Unknown)Latest Amazon Interview Questions -3http://placementsindia.blogspot.com/2007/12/latest-amazon-interview-questions-3.htmlAmazonInterviewsThu, 19 Jun 2008 10:40:00 +0530tag:blogger.com,1999:blog-32064785.post-64968349817718498111. How would you find the second largest element in an array using minimum no of comparisons?<br /><br />2. Write a C program for level order traversal of a tree?<br /><br />3. You are given: 3 types of vehicles: Motorbike, Car, and a special type of car for the handicapped. <br /> 3 types of parking: Motorbike parking, Car parking, handicapped car parking.<br /><br />Motorbikes and cars can only park in their designated parkings, while the handicapped cars can park either in their own parking or the regular car parking.<br />How would you model this as classes? Explain your methods.<br /><br /><br />4. Given 2 tables: Employee(Employee_Name,Dept_No) Department(Dept_No, Dept_Name)<br /><br />Write an SQL query which outputs all the employees, and their department nos and names, including all those departments which have no employees working for them.<br /><br />6. Explain about Inodes?<br /><br />7.Give a Linux shell command to find all files in a directory which contain ip addresses.<br /><br />8. Given a table Employee which has columns name and salary, write an SQL query to find the employee with the second highest salary.<br /><br />9. Given a table of Player which contains Sno and player name, write a query which finds all possible Table Tennis doubles pairings.<br /><br />10.Given a string A, and a string B, and a dictionary, how would you convert A to B in the minimum no of operations, given that:<br /><br />i) All the intermediate words must be from the dictionary<br /><br />ii) An ‘operation’ is defined as:<br /><br />a) Delete any character from a string ex dog → do<br /><br />b) Insert any character into a string ex cat → cart<br /><br />c) Replace any character in the string with another ex cat → cot4kchaitanyya@gmail.com (Unknown)Latest Amazon Interview Questions -2http://placementsindia.blogspot.com/2007/12/latest-amazon-interview-questions-2.htmlAmazonInterviewsMon, 9 Jun 2008 19:16:00 +0530tag:blogger.com,1999:blog-32064785.post-21831765605355592021.Given a string,find the first un-repeated character in it? Give some test cases<br /><br />2.You are given a dictionary of all valid words. You have the following 3 operations permitted on a word:<br /><br />a) Delete a character<br /><br />b) Insert a character<br /><br />c) Replace a character<br /><br />Now given two words - word1 and word2 - find the minimum number of steps required to convert word1 to word2. (one operation counts as 1 step.)<br /><br /><br />3.Given a cube of size n*n*n (i.e made up of n^3 smaller cubes), find the number of smaller cubes on the surface. Extend this to k-dimension.<br /><br />4.What is a C array and illustrate the how is it different from a list.<br /><br />5. What is the time and space complexities of merge sort and when is it preferred over quick sort?<br /><br />6. Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.<br /><br />7. Given n red balls and m blue balls and some containers, how would you distribute those balls among the containers such that the probability of picking a red ball is maximized, assuming that the user randomly chooses a container and then randomly picks a ball from that.<br /><br />8.Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.<br /><br />9. Given an array of size n ,containing every element from 1 to n+1, except one. Find the missing element.5kchaitanyya@gmail.com (Unknown)Latest Amazon Interview Questions -1http://placementsindia.blogspot.com/2007/12/latest-amazaon-interview-questions-1.htmlAmazonInterviewsTue, 3 Jun 2008 21:57:00 +0530tag:blogger.com,1999:blog-32064785.post-47245900347393641711. How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same<br /><br />2. Explain polymorphism citing an example.<br /><br />3. What are the 4 basics of OOP?<br /><br />4. Define Data Abstraction. What is its importance?<br /><br />5. Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array.<br /><br />Eg.<br /><br />i) 3 2 7 10 should return 13 (sum of 3 and 10)<br /><br />ii) 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)<br /><br /><br />6. Given a Binary Search Tree, write a program to print the kth smallest element without using any static/global variable. You can’t pass the value k to any function also. <br /><br />7.You are given some denominations of coins in an array (int denom[])and infinite supply of all of them. Given an amount (int amount), find the minimum number of coins required to get the exact amount. What is the method called?<br /><br />8.Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 1 number. Find the missing number.<br /><br />9.Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 2 numbers. Find the missing numbers.<br /><br />10.Given an array of size n. It contains numbers in the range 1 to n. Find the numbers which aren't present.10kchaitanyya@gmail.com (Unknown)Search In A Young tableau - A Sorted Matrixhttp://placementsindia.blogspot.com/2008/05/search-in-young-tableau-sorted-matrix.htmlAlgorithm AnalysisThu, 22 May 2008 10:31:00 +0530tag:blogger.com,1999:blog-32064785.post-8616626232370039183<span style="font-weight: bold;">Young tableau : </span>For our present discussion ,we confine this entity to a table which elements are sorted both column wise and row wise.The degree of orderliness among the elements is loosely bound that a row by row or column by column traversal of this matrix doesn't essentially list out the elements in a sorted manner.So the search on this matrix is not all that simple and straight forward as it looks like.<br />In the following sections we will look at some interesting approaches to search for a key in this 2D array(after all it is!!).<br /><br />One interesting yet simple thing worth observing is that<br />element A[i][j] is always > A[p][q] for i > p and j> q .<br />The next 2 strategies are based on this simple fact.<br /><br /><span style="font-style: italic;">Strategy1 - A grid search</span>: About any element A[i][i] divide the matrix in to 4 quadrants.<br />If the key K we are looking for is<br /><ol><br /><li> <A[i][j] then we can eliminate the lower right quadrant because all its elements are > A[i][j].</li><br /><li> <A[i][j] then we can eliminate the lower right quadrant because all its elements are > A[i][j].</li><br /><li>=A[i][j]. then our search is over.The choice of this i can be done in a binary search manner.. reducing the search space by half.</li></ol><br /><br />Now we can search the 3 quadrants individually and hence recursively.<br /><br />T(N)=3*T(N/4)+O(1) which comes out to be O(N^(log3/log4)) which is less than O(N).<br /><br /><span style="font-style: italic;">Strategy2:</span>Now we move a step further in reducing the search space.Iterate along the diagonal and find i such that A[i][i] <k and A[i+1][i+1] >k.Now we have only 2 search intervals to search for.<br /><br />T(N)=2*T(N/4)+O(N) which comes out to be O(N).<br /><br />Strategy3:One more interesting solution and smart solution that I found was(the credit goes to the geek named Novice in the discussion http://inder-gnu.blogspot.com/2008/01/find-element-in-row-and-column-sorted.html ) this.<br /><br />Start from the point in the last row first column. Every point to its right is greater than this point and every point on its top is smaller than this. So, if the point is greater than this point then move right otherwise move top. So, you will traverse at most 2*n points.<br /><br /><br />Well, these are 3 interesting solutions I could find till now and at this juncture ,it is not surprising if one wishes to compare these strategies to figure out the best and I don't even rule out any other solutions to this problem.So folks if you do any ,please put them in the comments sections and let others know.<br /><br /><span style="font-weight:bold;">Continued</span><br /><br />Here are the C codes for the above discussed strategies.<br /><br /><span style="font-weight:bold;">Strategy1</span><br /><br /><br /><br /><br /><span style="font-weight:bold;">strategy1</span><br /><pre><br />bool novice_search(int **grid,int size, int key,int &x,int &y)<br />{<br /> int i=size-1,j=0;<br /> while(0<=i && i<size && 0<=j && j<size)<br /> {<br /> if(grid[i][j]==key)<br /> {<br /> x=i;<br /> y=j;<br /> return true;<br /> }<br /> else if(grid[i][j] <key)<br /> {<br /> j++;<br /> }<br /> else<br /> i--;<br /> }<br /> return false;<br />}<br /><br /></pre><br /><br /><span style="font-weight:bold;">strategy2</span><br /><pre><br />bool quadra_partitionsearch(int **grid,int row_min,int row_max,int col_min,int col_max,int key,int &x,int &y)<br />{<br /> if((row_min > row_max) ||( col_min >col_max))<br /> return false;<br /> else if((row_min==row_max) &&(col_min==col_max))<br /> {<br /> if(grid[row_min][col_min]==key)<br /> {<br /> x=row_min;<br /> y=col_min;<br /> return true;<br /> }<br /> else<br /> return false;<br /> }<br /> else if((grid[row_min][col_min] <=key) && (grid[row_max][col_max]>=key))<br /> {<br /> int row_mid =(row_min +row_max)/2;<br /> int col_mid =(col_min+col_max)/2;<br /> bool flag;<br /> // cout <<row_min <<'\t' <<row_max<<'\t'<<col_min<<'\t'<<col_max<<'\n';<br /> if(grid[row_mid][col_mid]==key)<br /> {<br /> x=row_mid;<br /> y=col_mid;<br /> return true;<br /> }<br /><br /> else if(grid[row_mid][col_mid]>key)<br /> {<br /> if(quadra_partitionsearch(grid,row_min,row_mid,col_min,col_mid,key,x,y))<br /> return true;<br /> }<br /> else<br /> {<br /> if(quadra_partitionsearch(grid,row_mid,row_max,col_mid+1,col_max,key,x,y))<br /> return true;<br /> }<br /> if(quadra_partitionsearch(grid,row_min,row_mid,col_mid+1,col_max,key,x,y))<br /> return true;<br /> else if(quadra_partitionsearch(grid,row_mid+1,row_max,col_min,col_mid,key,x,y))<br /> return true;<br /><br /> }<br /> return false;<br />}<br /><br /></pre><br /><span style="font-weight:bold;">strategy3</span><br /><pre><br />bool binary_partitionsearch(int **grid,int row_min,int row_max,int col_min,int col_max,int key,int &x,int &y)<br />{<br /> if((row_min > row_max) ||( col_min >col_max))<br /> return false;<br /> else if((row_min==row_max) &&(col_min==col_max))<br /> {<br /> if(grid[row_min][col_min]==key)<br /> {<br /> x=row_min;<br /> y=col_min;<br /> return true;<br /> }<br /> else<br /> return false;<br /> }<br /> else<br /> {<br /> if(grid[row_min][col_min] > key)<br /> return false;<br /> int row_mid=row_min,col_mid=col_min;<br /> while(grid[row_mid][col_mid] < key)<br /> {<br /> row_mid++;<br /> col_mid++;<br /> }<br /> if(grid[row_mid][col_mid]==key)<br /> {<br /> x=row_mid;<br /> y=col_mid;<br /> return true;<br /> }<br /> else<br /> {<br /> if(binary_partitionsearch(grid,row_mid,row_max,col_min,col_mid-1,key,x,y))<br /> return true;<br /> return binary_partitionsearch(grid,row_min,row_mid -1,col_mid,col_max,key,x,y);<br /> }<br /> }<br />}<br /><br /></pre><br />I tried to check which of them is efficient by noting the runtimes and well all of them were quite close,though 2nd and 3rd approaches did mostly well compared to the first one.All these strategies worked more or less in the same manner on an grids of size varying from 100 to 1000.The last 2 strategies worked much better than the first one mostly.19kchaitanyya@gmail.com (Unknown)Solutions to Crazy Questions at Google Job Interviewhttp://placementsindia.blogspot.com/2008/05/solutions-to-crazy-questions-at-google.htmlGoogleWed, 14 May 2008 21:51:00 +0530tag:blogger.com,1999:blog-32064785.post-1731991309438576097We are providing solutions to the <a href="http://tihomir.org/crazy-questions-at-google-job-interview/">Crazy Questions at Google Job Interview</a> post By <a href="http://tihomir.org/">Thiomir</a><br /><br /><ol><br /><li>How many golf balls can fit in a school bus?<br /><br /><strong>Solution:</strong> The point of the question isn't to see how golf balls you think are in the bus, but to see what your deduction skills are like. Do you just make a random guess or try to cop out by saying a lot, or do you actually try to come up with a legitimate answer by going through a logical series of steps.<br /></li><br /><br /><li>You are shrunk to the height of a nickel and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The blades will start moving in 60 seconds. What do you do?<br /><br /><br /><strong>Solution:</strong>You simply jump out. As you are scaled down, the ratio of muscle mass to total mass remains the same. Potential energy is given by E = mgh. So, if E/m is unchanged (where E is the energy expended in expanding your leg muscles, and m is your mass), then h is unchanged. Mini-me jumps as high as me. This is the reason why grass-hoppers can jump about as high as people.<br /></li><br /><br /><li>How much should you charge to wash all the windows in Seattle?<br /><br /><strong>Solution:</strong>As crazy as it might sound, questions like these demonstrate your ability to think through a complex problem with little or no information. They expect you to take an educated guess. Most of the time you can ask them questions like - how many buildings are there in Seattle.<br /></li><br /><br /><li>How would you find out if a machine’s stack grows up or down in memory?<br /><br /><strong>Solution:</strong>Instantiate a local variable. Call another function with a local. Look at the address of that function and then compare. If the function's local is higher, the stack grows away from address location 0; if the function's local is lower, the stack grows towards address location 0.<br /></li><br /><br /><li>Explain a database in three sentences to your eight-year-old nephew.<br /><br /><strong>Solution:</strong>A database is like a file cabinet. The files, or data, is stored in it and can be arranged in categories. But unlike an actual file cabinet, you can do a lot more cool stuff with a database like being able to make it accessible through the internet.<br /></li><br /><br /><li>How many times a day does a clock’s hands overlap?<br /><br /><strong>Solution:</strong>The Hour hand and Minute hand would be meeting exactly 11 times in 12 hours (Hour hand would have taken 1 clockwise round and Minute hand would have taken 12 clockwise rounds, so 12 - 1 = 11 rounds).<br /><br />result: First time hour and minute hands overlap will be 12 Hours / 11 = 01:05:27.27. So at this time only hour and minute hands would be overlapping and second hand will not be any near to them. Similarly for 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th and 10th overlap of hour and minute hand the Second hand wont be any nearby. So all 3 hands (hour, minute and Second) overlap only 2 times i.e. (0:0:0 and 12:0:0).<br /><br />Also we all know when we get our watches repaired, normally the repairman overlaps all the three hands to 12.<br /><br />If we are considering that the second hand is not present, then the rest two overlaps 22 times in 24 hours.<br /><br />There again is a catch, if we check the angles by which the hour hand and minute hand moves.<br /><br />The second hand moves 6 degree in a second. In that time the minute hand will move 6/60 degrees. and the hour hand will move 6/(60*12) degrees. now taking these things in the considerations. if we check the positions of the hour and minute hand in terms of angle from the marker 12, for our first rendezvous time, i.e. 01:05:27.27 sec.<br />first thing that comes to my mind is that, there is fraction in the seconds. So that time can’t be measured. there will be no exact overlap. now lets calculate the angles:<br /><br />1 hour 5 mins and 27 seconds = 3600 + 5*60 + 27 = 3927 seconds.<br /><br />angle of hour hand = 3927 * 6/(60*12) = 32.725 degree.<br />angle of minute hand = 3927 * 6/60 = 392.7 degree<br />subtracting 360 degree from it we get - 32.7 degree.<br /><br />So at 01:05:27 both hands don’t overlap. Now for 01:05:28 :<br />Angles : hour hand - 32.73333<br />minute hand - 32.8<br />so obviously they dont meet at 01:05:28 either.<br /><br />So they overlap at 12:00 and 24:00 only. So the answer is 2 only.<br /><br /></li><br /><br /><li>You have to get from point A to point B. You don’t know if you can get there. What would you do?<br /><br /><strong>Solution:</strong>Utilizing a “learn as you go” approach and applying collected knowledge and data along the way is the best way to proceed. Let’s break this down farther.<br /><br />Determine the amount of time you have to go from point A to point B. Spend the initial 20% of that time making a 360° search with the largest circumference possible with the in the time you have allowed.<br /><br />During that time, ask people, look for maps, clues, collect data, and knowledge. At the end of the initial 360° search take an objective look at all the information you have obtained and you calculate the risk of failure you are willing to live with. Create a plan and a strategy based on your assessment of where you believe point B to be. Then you proceed on implementing your plan with predetermined intervals of reassessment and strategy improvements.<br /><br />This is the best chance you have reaching point B if you don’t know if you can get there.<br /></li><br /><br /><li>Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval?<br /><br /><strong>Solution:</strong>Let’s suppose there are<br />a set of attributes of each shirt you are interested in: e.g. sleeve length, color, buttons (no buttons, fully button, partially buttoned from collar to chest level).<br />Let’s say the closet is a simple wall closet with a single closet rod running the entire length of closet. On the left you put all the short sleeve shirts, and on the right the long sleeve shorts. You separate then long and short sleeve sides with a specially marked coat hanger. Then you separate each group into no buttonoed, partially buttoned, and fully button, using more specially marked hangers. Then each sub group is separated into colored and monochrome sub-sub-groups (specially marked hangers aren’t needed for separators unless you are color blind) Then each colored group is sorted left to right according to the color spectrum: ROYGBIV: red, orange, yellow, green, blue, indigo, violet. Each monochrome ggroup is sorted left to right: white on the left, black on the right, and shades of grey in the middle, the darker greys on the right, the lighter on the left.<br /></li><br /><br /><li>Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announces that at least one husband has been unfaithful. What happens?<br /><br /><strong>Solution:</strong>1. There is only one cheat husband<br />- If it is so then 99 wives knew it before. So the cheated wife got the idea from queen that her husband is cheating. So she will kill him. Next morning every wife will know there is no cheat husbands anymore.<br /><br /><br />2. There are more than one cheat husbands<br /><br />- In this case, all of the wives already had the idea prior to queen's information. Its just that the cheated wives knew the count which is one less than what the non-cheated wives' knew - thats all. i.e. if there were 2 cheat husbands then their wives knew the count is 1 and others knew its 2. So the queen just repeated the info saying "at least 1". Same goes to 2,3,4...100 cheat husbands. So in this case no wife kills her husband.<br /></li><br /><br /><li>In a country in which people only want boys, every family continues to have children until they have a boy. if they have a girl, they have another child. if they have a boy, they stop. what is the proportion of boys to girls in the country?<br /><br /><strong>Solution:</strong>From pure probability,we get the expected number of girls born to be 1/2 with that of boys being 1.So the ratio is 2:1<br /></li><br /><br /><li>If the probability of observing a car in 30 minutes on a highway is 0.95, what is the probability of observing a car in 10 minutes (assuming constant default probability)?<br /><br /><strong>Solution:</strong>If the chance to see the car is 10 percent per minute, the first minute you have 10% chance, the second minute you have 10% of 90% = 9% (so total 19%), the third minute 10% of 81% (= 8,1%, total 27,1 %) ......<br />As the chance for 30 minutes is 95 percent, the chance for 1 minute is 9.5% and for 10 minute 63.1 %.<br /></li><br /><br /><li>If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands? (The answer to this is not zero!)<br /><br /><strong>Solution:</strong>7.5 degrees (the hour hand is 1/4th of the way between 3 and 4, the angle measure of that is 360/12 = 30 degrees between hours / 4 = 7.5 degrees).</li><br /><br /><li>Four people need to cross a rickety rope bridge to get back to their camp at night. Unfortunately, they only have one flashlight and it only has enough light left for seventeen minutes. The bridge is too dangerous to cross without a flashlight, and it�s only strong enough to support two people at any given time. Each of the campers walks at a different speed. One can cross the bridge in 1 minute, another in 2 minutes, the third in 5 minutes, and the slow poke takes 10 minutes to cross. How do the campers make it across in 17 minutes?<br /><br /><strong>Solution:</strong>1 and 2 cross, taking 2 minutes, 1 goes back carrying the flashlight total=3 minutes. 5 and 10 cross, taking 10 minutes totaltime now= 13 minutes, 2 goes back,total time now = 15 minutes. 1 and 2 cross again, taking 2 minutes making it 17 minutes.<br /></li><br /><br /><li>You are at a party with a friend and 10 people are present including you and the friend. your friend makes you a wager that for every person you find that has the same birthday as you, you get $1; for every person he finds that does not have the same birthday as you, he gets $2. would you accept the wager?<br /><br /><strong>Solution:</strong>No.<br /></li><br /><br /><li>How many piano tuners are there in the entire world?<br /><br /><strong>Solution:</strong>1) At first list out all the piano manufacturing companies in the world.<br />2) Then look into their purchase records and find out the piano purchasers information.<br />3) i) If the purchase is made by an individual or a house hold then the piano is played at best case by all the people of the house.<br />ii) Else if the piano is purchased for school then list out the students that opted the piano course in their music curriculum.<br />iii) If the piano is purchased by a Church then count the no of major or minor events of the church and count the piano users.<br />sum up all the numbers to get more or less accurate piano users count.</li><br /><br /><li>You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two weighings?<br /><br /><strong>Solution:</strong>choose 6 balls and weigh 3 against 3<br />- if they weigh the same, you have another weighing for the remaining 2 balls and you can find the heavier one<br />- if they don’t weigh the same, from the group of 3 which was heavier, choose any 2 balls and weigh them:<br />- if they weigh the same, the remaining ball is the heavier one; otherwise you just found the heavier one by weighing the 2 chosen balls.<br /></li><br /><br /><li>You have five pirates, ranked from 5 to 1 in descending order. The top pirate has the right to propose how 100 gold coins should be divided among them. But the others get to vote on his plan, and if fewer than half agree with him, he gets killed. How should he allocate the gold in order to maximize his share but live to enjoy it? (Hint: One pirate ends up with 98 percent of the gold.)<br /><br /><strong>Solution:</strong>The highest ranked pirate gets 98 gold coins<br />---Two pirates get 1 gold coin each<br />---The other 2 pirates get nothing.<br /></li><br /></ol>16kchaitanyya@gmail.com (chaitanya)Google Interview Questionshttp://placementsindia.blogspot.com/2007/09/google-interview-questions.htmlGoogleWed, 30 Apr 2008 14:02:00 +0530tag:blogger.com,1999:blog-32064785.post-4988565250416814573<span style="font-weight: bold;"><a href="http://placementsindia.blogspot.com/2007/09/google-interview-questions.html">Google Interview Questions</a> ::</span><br /><br />Total there are five Technical Interviews followed by Management round.<br /><br />So here are the questions.<br /><br /><span style="font-weight: bold;"><a href="http://placementsindia.blogspot.com/2007/09/google-interview-questions.html">Google Interview Round 1</a> ::</span><br /><br /><ol><li>What is the Space complexity of quick sort algorithm? how do find it?<br /><br /><strong>Solution:</strong> Quicksort has a space complexity of O(logn), even in the worst case, when it is carefully implemented such that<br /> * in-place partitioning is used. This requires O(1).<br /> * After partitioning, the partition with the fewest elements is (recursively) sorted first, requiring at most O(logn) space. Then the other partition is sorted using tail-recursion or iteration.<br />The version of quicksort with in-place partitioning uses only constant additional space before making any recursive call. However, if it has made O(logn) nested recursive calls, it needs to store a constant amount of information from each of them. Since the best case makes at most O(logn) nested recursive calls, it uses O(logn) space. The worst case makes O(n) nested recursive calls, and so needs O(n) space.<br /><br />However, if we consider sorting arbitrarily large lists, we have to keep in mind that our variables like left and right can no longer be considered to occupy constant space; it takes O(logn) bits to index into a list of n items. Because we have variables like this in every stack frame, in reality quicksort requires O(log2n) bits of space in the best and average case and O(nlogn) space in the worst case. This isn't too terrible, though, since if the list contains mostly distinct elements, the list itself will also occupy O(nlogn) bits of space.<br /></li><br /><br /><li>What are dangling pointers?<br /><br /><strong>Solution:</strong> A dangling pointer is a pointer to storage that is no longer allocated. Dangling pointers are nasty bugs because they seldom crash the program until long after they have been created, which makes them hard to find. Programs that create dangling pointers often appear to work on small inputs, but are likely to fail on large or complex inputs.<br /></li><br /><br /><li>Given that you can take one step or two steps forward from a given step. So find the total number of ways of reaching Nth step.<br /><br /><strong>Solution:</strong>The simple recurrence relation governing this problem is f(N)=f(N-1) +f(N-2)(why?),which is a fibonacci sequence.<br />Nth state can be arrived directly by taking 2 step movement from N-2 or 1 step from N-1.Remember N-2 -> N-1 -> N is not a direct path from N-2th state to Nth state.Hence the no of solutions is no of ways to reach N-2th step and then directly taking a 2 jump step to N + no of ways to reach N-1th step and then taking 1 step advance.<br /></li><br /><br /><li>You are given biased coin. Find unbiased decision out of it?<br /><br /><strong>Solution:</strong>Throw the biased coin twice.Classify it as true for HT and false for TH.Both of these occur with probability=p*(1-p),hence unbiased. Ignore the other 2 events namely HH and TT.<br /><br /></li><br /><br /><li>On a empty chessboard, a horse starts from a point( say location x,y) and it starts moving randomly, but once it moves out of board, it cant come inside. So what is the total probability that it stays within the board after N steps.<br /><br /></li><br /></ol><br /><br /><span style="font-weight: bold;"><a href="http://placementsindia.blogspot.com/2007/09/google-interview-questions.html">Google Interview Round 2</a> ::</span><br /><br /><ol><li>You have 1 to N-1 array and 1 to N numbers, and one number is missing, you need to find the missing the number. Now you have 1 to N-2 numbers, and two numbers missing. Find them.<br /><br /><strong>Solution:</strong><br />The question can be elucidated as follows.Given an array of size N-1 containing numbers less than N and with out any duplicates!! We knew that there is a number missing from the array say K .Let S be the sum of the elements of the array.<br /><br />Sum of first N natural numbers=N*(N+1)/2 <br /><br />and S=N*(N+1)/2 - K.Now putting this other way around we get K=N*(N+1)/2 -S !!<br /><br /><br /><br />Now the second part of the question says that there are 2 of the first N numbers missing.Let they be X and Y. <br /><br />We solve this problem by solving 2 essential equations.<br /><br /><br /><br />They are X+Y=N*(N+1)/2 -S---------->(1)<br /><br /> X*Y=N!/P-------------------(2) where S and P are the cumulative sum and product of the array entries.<br /></li><br /><li>You have cycle in linked list. Find it. Prove that time complexity is linear. Also find the node at which looping takes place.<br /><br /><strong>Solution:</strong><br />The problem of checking whether there is a cycle or not can be solved using 2 pointers one moving in increments of 1 and the other in increments of 2.If there is a cycle then these 2 pointers meet at some node say N1 inside the cycle otherwise the fast pointer reaches the end of the list.This is a O(N) solution.<br /><br /> Now coming to the identification of the node at which looping took place.After our identification of cycle ,both the pointers P1 and P2 are at node N1.Now iterate the slow pointer to count the no of nodes in the cycle.(After traversing the whole cycle P1 and P2 shall again be at the same node).Let this size be K.Now take one of the pointers to the head node and count the no of nodes till N1.Let this number be X.Now use one of these pointers to reverse the cycle starting from N1.Only the cycle gets reversed.Now again traverse from head node to N1.Let the number of nodes this time be Y.Let the no of nodes from head to the start node of the cycle be Z<br /><br />Now X+Y=2*Z+K .Hence solve for K and then having figured out the start node N2 of the cycle.Now as the cycle is reversed having figured out this start node its next node is the looping nodes so set the looping nodes next pointer to NULL and reverse the list further till you reach N2.<br /></li><br /><br /><li>Questions on my project please be prepare well about your project</li><br /><br /><li>How do you search for a word in a large database.</li><li>How do you build address bar in say gmail. i.e. if you press 'r' then you get all email starting from 'r', and if you press 'ra' then you will get emails starting from 'ra'.</li></ol><br /><span style="font-weight: bold;"><a href="http://placementsindia.blogspot.com/2007/09/google-interview-questions.html">Google Interview Round 3</a> ::</span><br /><br /><ol><li>You have given an array. Find the maximum and minimum numbers in less number of comparisons.<br /><br /><strong>Solution:</strong><br />only 3n/2 comparisons are necessary to find both the minimum and the maximum. To do this, we maintain the minimum and maximum elements seen thus far. Rather than processing each element of the input by comparing it against the current minimum and maximum, however, at a cost of two comparisons per element, we process elements in pairs. We compare pairs of elements from the input first with each other, and then compare the smaller to the current minimum and the larger to the current maximum, at a cost of three comparisons for every two elements.<br /></li><br /><li>You have given an array from 1 to N and numbers also from 1 to N. But more than one number is missing and some numbers have repeated more than once. Find the algo with running time O(n).<br /><br /><strong>Solution:</strong>All the numbers are positive to start with.Now, For each A[i], Check the sign of A[A[i]]. Make A[A[i]] negative if it's positive. Report a repetition if it's negative.Finally all those entries i,for which A[i] is negative are present and those i for which A[i] is positive are absent.<br /><br /></li></ol><br /><span style="font-weight: bold;"><a href="http://placementsindia.blogspot.com/2007/09/google-interview-questions.html">Google Interview Round 4</a> ::</span><br /><br /><ol><li>Three strings say A,B,C are given to you. Check weather 3rd string is interleaved from string A and B.<br /><pre> Ex: A="abcd" B="xyz" C="axybczd". answer is yes.</pre><br /><br /><strong>Solution:</strong><br /><pre><br />bool test(A,B,C)<br />{<br /> i=j=k=0;<br /> while(k < C.size())<br /> {<br /> if(i < A.size() && C[k]==A[i])<br /> {i++,k++;<br /> }<br /> else if(j < B.size() && C[k]==B[j])<br /> {<br /> j++,k++;<br /> }<br /> else<br /> return false <br /> }<br /> return (i == A.size() && j == B.size());<br />} <br /></pre><br />The above algorithm doesn't work when C[k]=A[i]=B[j], essentially throwing one in to a dilemma whether to accept the character from A or B.<br /></li><br /><br /><li>Given two sorted arrays A and B. <br /></li><ol><li>Find the intersection of these arrays A and B.<br /><br /><strong>Solution:</strong>The intersection can be found by using a variation of merge routine of the merge sort.<br /></li><br /><br /><li>If array A is small and array B is too large. how will you proceed for getting intersection of those two arrays?<br /><br /><strong>Solution:</strong>In this case for each entry of smaller array,we can run a binary search routine on the larger one to know its presence.<br /></li></ol></ol><br /><span style="font-weight: bold;"><a href="http://placementsindia.blogspot.com/2007/09/google-interview-questions.html">Google Interview Round 5</a> ::</span><br /><br /><ol><li>If you get into Google, which products are you going to work on?</li><li>What is TCP, UDP. what is reliability, unreliability, give examples of these?<br /><br /><strong>Solution:</strong><br /><a href="http://en.wikipedia.org/wiki/Transmission_Control_Protocol">Click Here To Read About TCP</a><br /><a href="http://en.wikipedia.org/wiki/User_Datagram_Protocol">Click Here To Read About UDP</a><br /><a href="http://en.wikipedia.org/wiki/Reliability_%28computer_networking%29">Click Here To Read About Reliability</a><br /></li><br /><li>What is http protocol?<br /><br /><strong>Solution:</strong><br /><a href="http://en.wikipedia.org/wiki/HTTP">Click Here To Read About HTTP</a><br /><br /></li><li>How does Google search engine works?</li><li>What is indexing, what is the input and output to it. how Google does that?</li></ol><br />This was the interview i got from one of my friends. Discuss them here. <span style="font-weight: bold;">If you had attended Google Interview share you interview experience with us</span>.You can post the questions through comments section or you can mail me at kchaitanyya@gmail.com14kchaitanyya@gmail.com (chaitanya)Google Fresher's latest Interview Questionshttp://placementsindia.blogspot.com/2007/08/google-freshers-latest-interview.htmlGoogleWed, 23 Apr 2008 21:21:00 +0530tag:blogger.com,1999:blog-32064785.post-4790248902321255343<a href="http://placementsindia.blogspot.com/2007/08/google-freshers-latest-interview.html"><span style="font-weight: bold">Google telephonic Interview</span></a> <ol> <li>Asked about my project. Prepare well to answer any type of questions that may arise in your project.They will just ask to explain about any one of the projects listed in your resume. </li> <li>In a plane, n points are given i.e. the input is (x1,y1), (x2,y2)... (xn,yn). Now given these n points.Find the maximum number of collinear points. <br /><strong>Solution:</strong> <br />The duality algorithm would work. Find the point of intersection with maximum no of lines incident on it in the dual plane. It works in O(n^2). </li> <li>Write the code for finding the min of n number. <pre>I gave:<br /><br />for(i=0;i<n;i++)<br />{<br /> if( a[i]<min )<br /> {<br /> min = a[i] ---- eq(i)<br /> }<br />}<br /></pre><br />Given that n numbers are from random sampling how many times (probability) does the line (i) be executed <br /><br /> <br /><strong>Solution:</strong> <br /><br /> <pre>min=a[0];<br />for(i=1;i<n;i++)<br />{<br /> if( a[i]<min ) <br /> {<br /><br /> min = a[i]; -------eq(i) <br /> }<br /><br />}</pre><br />Once the variable min is initialized,the probability of a[i] < min is 1/2. So the expected number of occurances of equation i is (n-1)/2 . </li><br /></ol><br /><span style="font-weight: bold"><a href="http://placementsindia.blogspot.com/2007/08/google-freshers-latest-interview.html">Google Interview Round 2</a>:</span> <br /><br /><ol><br /> <li>What is Bottom up parsing and what is top down parsing? <br /> <br /><strong>Solution:</strong> <br /><br /> <br /><strong>Bottom-up</strong> parsing is a strategy for analyzing unknown data relationships that attempts to identify the most fundamental units first, and then to infer higher-order structures from them. It attempts to build trees upward toward the start symbol. It occurs in the analysis of both natural languages and computer languages. <br /><br /> <br /><strong>Top-down</strong> parsing is a strategy of analyzing unknown data relationships by hypothesizing general parse tree structures and then considering whether the known fundamental structures are compatible with the hypothesis. It occurs in the analysis of both natural languages and computer languages. Please refer to these links for much better information. <br /><br /> <br /><a href="http://en.wikipedia.org/wiki/Bottom-up_parsing">http://en.wikipedia.org/wiki/Bottom-up_parsing</a> <br /><br /> <br /><a href="http://en.wikipedia.org/wiki/Top-down_parsing">http://en.wikipedia.org/wiki/Top-down_parsing</a> </li><br /><br /> <li>What is a symbol table? <br /> <br /><strong>Solution:</strong> <br />In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating to its declaration or appearance in the source, such as its type, scope level and sometimes its location.<br />Check out <br /><a href="http://en.wikipedia.org/wiki/Symbol_table"> http://en.wikipedia.org/wiki/Symbol_table</a></li><br /><br /><br /> <li>There is a portal with two billion users registered. If you store all the 2 billion users in a conventional databases it will take more time to retrieve the data about a particular user when that user tries to login. How do you handle this situation to make sure that the user gets the response quickly.<br /><br /><br /><strong>Solution:</strong><br />Every row has a primary key. Suppose the primary key for this<br />particular database is the name of the user then we can sort the names based<br />on alphabets and do secondary indexing based on the starting alphabet . If<br />the data is uniformly distributed we can go for multilevel indexing or<br />hashing.Similarly if we have a registration number as the primary key then<br />we can sort the table based on registration number and then do indexing<br />either secondary level or multilevel or apply hashing techniques based on<br />the distribution of data. Many efficient algorithms are available for<br />indexing and hashing.<br /><br /> </li><br /><br /> <li>There are 8 identical balls. One of them is defective. It could be either heavier of lighter. Given a common balance how do you find the defective ball in least number of weighings.<br /><br /><br /><strong>Solution:</strong><br />Weigh 3 balls against 3 others. <br /> <span style="font-weight:bold;">Case A:</span> If, on the first weighing, the balls balance, then the defective is among the 2 remaining balls and can be determined using 2 weighings making it a total of 3.<br /><br /> <span style="font-weight:bold;">Case B</span>:<br /><br /> <span style="font-style:italic;">Step1:</span> If, on the first weighing, the balls don't balance.<br /> If the balls do not balance on the first weighing, we know that the odd ball is one of the 6 balls that was weighed. We also know that the group of 2 unweighed balls are normal, and that one of the sides, let's say Side A, is heavier than the other (although we don't know whether the odd ball is heavy or light). <br /> <span style="font-style:italic;">Step 2 </span>: Take 2 balls from the unweighed group and use them to replace 2 balls on Side A (the heavy side). Take the 2 balls from Side A and use them to replace 2 balls on Side B (which are removed from the scale). <br /><br /> I. If the scale balances, we know that one of the 2 balls removed from the scale was the odd one. In this case, we know that the ball is also light. We can proceed with the third weighing amd determine the lighter of the 2 balls ,hance the defective.<br /><br /> II. If the scale tilts to the other side, so that Side B is now the heavy side, we know that one of the three balls moved from Side A to Side B is the odd ball, and that it is heavy. We proceed with the third weighing and determine the heavier one ,the defective. <br /><br /> III. If the scale remains the same, we know that one of the two balls on the scale that was not shifted in our second weighing is the odd ball. We also know that the unmoved ball from Side A is heavier than the unmoved ball on Side B (though we don't know whether the odd ball is heavy or light).<br /><br /><br /><br /><br /> <span style="font-style:italic;">Step 3 (for Case B)</span>: Weigh the ball from Side A against a normal ball. If the scale balances, the ball from Side B is the odd one, and is light. If the scale does not balance, the ball from Side A is the odd one, and is heavy.<br /><br /> </li><br /><br /> <li>You have all the English words with you. you would like to manage a dictionary so that you can look up when ever you have doubt. Which data structure would you like to use and why?<br /><br /><br /><strong>Solution:</strong><br />Dozens of different data structures have been proposed for implementing dictionaries including hash tables, skip lists, and balanced/unbalanced binary search trees -- so choosing the right one can be tricky. Depending on the application, it is also a decision that can significantly impact performance. In practice, it is more important to avoid using a bad data structure than to identify the single best option available.As the frequency of look ups for a word is also important,weighted binary search tree with weights in proportion to the frequency of lookups and determining the depth, can be effective.<br /></li><br /><br /><li>Asked me about all the details of hash table and heaps. </li><br /><br /><li>Write code for finding number of zeros in n!<br /><br /><br /><strong>Solution:</strong><br /><br />A zero in n! typically occurs when a multiple of 5 gets multiplied to an even number.We use this simple yet effective information to solve this problem.In the first n natural numbers,those divisible by 5 are always less than the no of even numbers.So it all boils down to the power of 5 in the prime factorization of n! .<br />This simple formula works for finding it floor(n/5)+floor(n/25)+floor(n/125)+......<br /><pre><br />function zeros(int n)<br />{<br /> int count=0,k=5;<br />while(n>=k)<br />{<br /> count+=n/k;<br /> k*=5;<br />}<br />return count;<br />}<br /></pre><br />this count is the number of o's in n!.<br /> <br /> </li><br /></ol><br /><br /><p><span style="font-weight: bold"><a href="http://placementsindia.blogspot.com/2007/08/google-freshers-latest-interview.html">Google Interview Round 3</a> :</span> </p><br /><br /><ol><br /> <li>Write C++ class for the game Connect Four. [Connect Four (also known as Plot Four, Four In A Row, and Four In A Line) is a two-player board game in which the players take turns in dropping discs into a seven column grid with the objective of getting four of one's own discs in a line.] </li><br /><br /> <li>Given a stack and an input string of 1234.At any point you can do anyone of the follow <br /> <pre>i. take the next input symbol and Enque.<br />ii. you can pop as many as you can. When ever you<br />pop an element it will be printed<br /> (you cannot pop from an empty stack)</pre><br />How many such permutations are possible on an input of size N?<br /><br /><br /><strong>Solution:</strong><br /> It is Nth catalan number.For a detailed solution look at question5 of <a href= "http://placementsindia.blogspot.com/2007/09/stack-and-queue.html">Stacks and Queues</a><br /><br /> </li><br /><br /> <li>Give an example of one permutation that this data structure cannot generate. <br /> <pre>For Example:<br /><br />1234 is input.<br /><br />First push all 1,2,3,4 on to stack and pop all.<br /> output will be 4321.</pre><br />It means that this data structure can generate 4321.<br /><br /><br /><strong>Solution:</strong><br />3124 <br /> for a detailed solution please look at question7 of the post<br /> <a href= "http://placementsindia.blogspot.com/2007/09/stack-and-queue.html">Stacks and Queues</a><br /><br /> </li><br /><br /> <li>Question 2 was pretty easy right? Now do again the same question but the data structure this time around is a Deque. <br /> <pre>Input: 12345<br />Data Structure: Deque ( Doubly Que )<br /><br />Note: Deque is a data structure into which you can do enque<br /> and deque from both sides.Some thing like this<br />__________________________________<br />enque ---> <----enque dequeue <---- ----->dequeue<br />__________________________________</pre><br /><br /><br /><strong>Solution:</strong> <br />It is N!. Guess why?(no constraints).Convince yourself by proving that every permutation can be generated by a set of valid operations.This prove can be using the principle of strong mathematical induction.So for this specific input the answer is 120.<br /></li><br /><br /> <li>Classic Egg Puzzle Problem You are given 2 eggs.You have access to a 100-store building. Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical.You need to figure out the highest floor of a 100-store building an egg can be dropped without breaking. Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process.<br /><br /><br /><strong>Solution:</strong> <br />Let "d" be the number of drops required to find out the max floor.we need to get the value of d.<br /><br />let's say if we drop from height d then if it breaks then we have d-1 floors to check for the second egg . so max of "d" drops, so first we will drop it from height "d" if it doesn't break at a height "d" then we are left with "d-1" drops,so lets drop it from d + 'd-2' + 1 height suppose if it break there then you are left with 'd-2' drops.<br />and so on until that sum is less than 100, it's like a linear search,<br /><br />in equations,<br /><br /> (1+(d-1))+ (1+(d-2)) + .... >= 100<br /><br />here we need to find out d<br /><br />from the above equation<br /><br />d(d + 1)/2 >= 100<br /><br /><br />from above d is 14<br /><br /><br /> </li><br /></ol><br /><br /><p><span style="font-weight: bold"><a href="http://placementsindia.blogspot.com/2007/08/google-freshers-latest-interview.html">Google Interview Round 4</a> :</span> </p><br /><br /><ol><br /> <li>Given n non overlapping intervals and an element. Find the interval into which this element falls.<br /><br /><br /><strong>Solution:</strong> <br />we can extend binary search to intervals.(Assuming the intervals are sorted)<br />consider interval [a,b].<br />if (a-x)(b-x) <=0 <br /> then x belongs to [a,b].<br />else<br /> if x>a <br /> element can be present only in the intervals to its right. <br /> so select the middle interval among them to it's right<br /> and repeat the procedure.<br /> else<br /> element can be present only in the intervals to its left. <br /> so select the middle interval among them to it's left<br /> and repeat the procedure.<br /><br />The complexity of this problem is log(N) where N is the number of sorted non-overlapping intervals.<br /> </li><br /><br /> <li>Worst case is take all intervals one at a time and see whether the element lies in the interval or not.It will take O(n). So please give a solution that will do better than O(n). </li><br /><br /> <li>Now given that the n intervals are overlapping then how do you solve? The interviewer was concentrating more on the complexities (running, memory ..) <br /><br /><br /><strong>Solution:</strong> <br />If the above intervals are overlapping ,then they can be merged in O(N) and then the exact intervals can be resolved later.Otherwise ,we can identify one correct interval and then linear search on its left and right neighbourhood to find the other solutions.<br /> <br /><br /></li><br /><br /> <li>Write code for Random Sort? <br /> <pre>Algorithm is explained:<br /><br />Given an input array of size n. Random sort is sampling<br />a new array from the given array and check whether the<br />sampled array is sorted or not. If sorted return else<br />sample again. The stress was on the<br />code.</pre><br /> </li><br /></ol><br /><br /><p><span style="font-weight: bold"><a href="http://placementsindia.blogspot.com/2007/08/google-freshers-latest-interview.html">Google Interview Round 5</a>:</span> This is Manager Round </p><br /><br /><ol><br /> <li>Tell me an achievement that you have done in your non academics </li><br /><br /> <li>Tell me about one of your project </li><br /><br /> <li>Take a feature of C++ and tell me how you have implemented it in one of your project </li><br /><br /> <li>By taking one of your project as example tell me how you have taken care of software engineering where you would have handled more data </li><br /><br /> <li>There is a routine already written to find the subtraction of two sets ( set A - set B) . Write test cases for testing it.Tell me how do you test the test cases you have written? </li><br /><br /> <li>There is a printed book. The page numbers are not printed. Now the printing of page numbers is being done separately. If the total number of digits printed is 1095 then how many pages does the book have? <br /><br /><br /><strong>Solution:</strong> Well people,this is too simple a question ..so do give it a try..(no malice,too simple).Any queries then do shoot a comment.<br /><br /></li><br /></ol>32kchaitanyya@gmail.com (chaitanya)Yahoo Interview Questionshttp://placementsindia.blogspot.com/2007/09/yahoo-interview-questions.htmlyahooThu, 27 Mar 2008 13:33:00 +0530tag:blogger.com,1999:blog-32064785.post-6188022626064210064<p><span style="font-weight: bold;">Yahoo Telephonic Round:</span> <br /> <br /><strong>Design classes for the following problem. (C++) <br /></strong> <br />A Customer Can have multiple bank accounts A Bank account can be owned by multiple customers When customer logs in he sees list of account, on clicking on an account he sees list of transactions.</p> <p><strong>Solution :</strong></p> <p>Customer class, Account class, Transaction class <br />Customer class contains an array of pointers to the account classes <br />Account class contains an array of pointers to its owner customer classes <br />Account class also contains an array of transactions associated to it. <br />Transaction class contains id or pointer the customer who did that transaction <br />In customer class write a function with prototype </p> <br /><pre>for (i in Accounts )<br />{<br /> cout << i.AccountName << endl; <br />} <br />cin >> id; <br />for(i in Accounts[id].transactions ) <br />{ <br /> cout << i.TransDetails << endl;<br />}</pre><br /><p> <br /><span style="font-weight: bold;">Yahoo Interview Round 1:</span> <br /></p> <ol> <li><strong>How to call a C++ function which is compiled with C++ compiler in C code? <br /></strong> <br /><strong>Solution:</strong> The C++ compiler must know that f(int,char,float) is to be called by a C compiler using the extern "C"construct: <br /> <br />The extern "C" line tells the compiler that the external information sent to the linker should use C calling conventions and name mangling (e.g., preceded by a single underscore). Since name overloading isn't supported by C, you can't make several overloaded functions simultaneously callable by a C program. <br /> <pre>// This is C++ code <br />// Declare f(int,char,float) using extern "C": <br />extern "C" void f(int i, char c, float x); <br />... <br />// Define f(int,char,float) in some C++ module: <br />void f(int i, char c, float x)<br />{ <br /> ..... <br />} </pre><br /> <br /></li> <li><strong>When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code) </strong></li> <li><strong>How do you initialize a static member of a class with return value of some function? </strong> <blockquote> <p><strong>Solution :</strong></p> <p>Static data members are shared by all object instances of that class. Each class instance sees and has access to the same static data. The static data is not part of the class object but is made available by the compiler whenever an object of that class comes into scope. Static data members, therefore, behave as global variables for a class. One of the trickiest ramifications of using a static data member in a class is that it must be initialized, just once, outside the class definition, in the source file. This is due to the fact a header file is typically seen multiple times by the compiler. If the compiler encountered the initialization of a variable multiple times it would be very difficult to ensure that variables were properly initialized. Hence, exactly one initialization of a static is allowed in the entire program. </p> <p>Consider the following class, A, with a static data member, _id: </p> <pre> <br /> //File: a.h<br /> class A<br /> {<br /> public:<br /> A();<br /> int _id;<br /> };</pre> <p>The initialization of a static member is done similarly to the way global variables are initialized at file scope, except that the class scope operator must be used. Typically, the definition is placed at the top of the class source file: </p><pre> // File: a.cc<br /> int A::_id;</pre><p>Because no explicit initial value was specified, the compiler will implicitly initialize _id to zero. An explicit initialization can also be specified: </p> <pre><br />// File: a.cc<br /> int A::_id = 999;<br /> </pre> <p>In fact, C++ even allows arbitrary expressions to be used in initializers: </p> <pre> // File: a.cc<br /> int A::_id = GetId(); </pre> </blockquote> </li> <li><strong>How can one application use same API provided by different vendors at the same time? </strong></li> <li><strong>If you are given the name of the function at run time how will you invoke the function? </strong> <blockquote> <p><strong>Solution :</strong></p> <ul> <li>Compile your program with --export-dynamic on the gcc command line </li> <li>Link with -ldl (dynamic library handling, needed for dlopen and dlsym </li> <li>Call dlopen() with a null parameter, meaning you aren't loading symbols from a file but from the current executable </li> <li>Call dlsym() with the name of the function you'll be calling. Note that C++ modifies function names, so If you're trying this with C++, you'd have to either declare this function as extern "C", or figure out what name the function has after compiling. (On unix, you could run nm -s on the object file for this). </li> <li>If dlsym() returns non-null, use the returned value as a function pointer to invoke your function. </li> </ul> </blockquote> </li> </ol> <span style="font-weight: bold;">Yahoo Interview Round 2:</span> <ol> <li><strong>When will you use shell script/Perl ahead of C/C++? </strong></li> <li><strong>How does yahoo handles billions of requests, does it create a thread per request or a process? </strong></li> <li><strong>How does HTTP works? </strong> <blockquote> <p><strong>Solution :</strong>HTTP Is a request-response protocol. </p> <p>For example, a Web browser initiates a request to a server, typically by opening a TCP/IP connection. The request itself comprises o a request line, o a set of request headers, and o an entity. The server sends a response that comprises o a status line, o a set of response headers, and o an entity. The entity in the request or response can be thought of simply as the payload, which may be binary data. The other items are readable ASCII characters. When the response has been completed, either the browser or the server may terminate the TCP/IP connection, or the browser can send another request. </p> </blockquote> </li> <li><strong>How to count number of unique music titles downloaded from a log file which contains an entry of all music title downloaded? </strong></li> <li><strong>What is the difference between COM and CORBA? </strong> <blockquote> <p><strong>Solution :</strong>COM is linked to Microsoft and CORBA to UNIX,Moreover, COM objects require installation on the machine from where it is being used .CORBA is ORB (Object request broker) , and also its a specification owned by OMG, which is open. Not owned by a company. So we cannot say that it only belongs to Unix. Corba servers can run on windows NT, and CORBA clients can run on Unix. </p> </blockquote> </li> <li><strong>What is web service? </strong> <blockquote> <p><strong>Solution :</strong>Web Service is defined as "a software system designed to support interoperable Machine to Machine interaction over a network." Web services are frequently just Web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services. </p> </blockquote> </li> </ol> <p>I got only these two Rounds as of now, if I get any more I will post them here. <span style="font-weight: bold;">If you have attended yahoo interview please share your experience and questions with us.</span> You can mail them at kchaitanyya@gmail.com or you can comment here.Solutions for rest of questions will be provided later.if you know any of the questions which are unsolved please comment the solution. we will include.</p>19kchaitanyya@gmail.com (chaitanya)Latest Microsoft Interview Questionshttp://placementsindia.blogspot.com/2008/02/latest-microsoft-interview-questions.htmlMicrosoftTue, 25 Mar 2008 14:59:00 +0530tag:blogger.com,1999:blog-32064785.post-6178698701005861209<ol> <li>Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. <br /></li> <li>Given a binary tree build a linked list of all its nodes such that the nodes of a level appear before the nodes of the next level? <br /></li> <li>Given an infinite stream of bits with the bits being appended at the highest significant position. give an algorithm to to say <a href="http://placementsindia.blogspot.com/2008/02/latest-microsoft-interview-questions.html">whether the number</a> formed by using the sequence of bits that had been processed till then, is divisible by 3 or not? <br /></li> <li>Given a string S of words and no of character per line m ,with m being greater than the longest word in S,print S in a set of lines so that each line contains no more than m characters and no word split between 2 lines. <br /></li> <li>Given an expression remove the unnecessary brackets in it with out creating an ambiguity in its execution. <code> <br /></code><code> input output </code> <br /><code> ex1: (a+(b)+c) a+b+c <br /> ex2: (a*b)+c a*b+c </code> <br /></li> <li>Propose a tree based data structure to identify a node with nth <a href="http://placementsindia.blogspot.com/2008/02/latest-microsoft-interview-questions.html">rank with maximum</a> efficiency . <br /></li> <li>Given a string S of alphabets and 2 characters a,b find the minimum distance between instances of them such that position of a <= position of b. <br /></li> <li>Given an array of size n with first l positions filled with characters and a string s ,replace all the instances of ’%’ with this string s,given that the length of the array is sufficient to handle these substitutions. <br /><code>input output </code> <br /><code>eg: abcdef%ghi%—— and “ppp” abcdefpppghippp </code> <br /></li> <li>Given a binary tree verify whether it is a binary search tree or not? <br /></li> <li>Write a C code to merge 2 binary search trees and do the same 2 merge linked lists.How is the former different when compared to the later.(Discuss the issues) <br /> <br /></li> </ol>9kchaitanyya@gmail.com (Unknown)Interview Questions on C Programming Variableshttp://placementsindia.blogspot.com/2008/03/scope-of-c-programming-variables.htmlCrackTheInterviewTue, 25 Mar 2008 14:37:00 +0530tag:blogger.com,1999:blog-32064785.post-3992193326007771896<ol> <li><strong>What is the difference between the declaration and the definition of a variable?</strong> <p>The definition is the one that actually allocates space, and provides an initialization value, if any. <br />There can be many declarations, but there must be exactly one definition. A definition tells the compiler to set aside storage for the variable. A declaration makes the variable known to parts of the program that may wish to use it. A variable might be defined and declared in the same statement. </p> </li> <li><strong>Do Global variables start out as zero?  <br /></strong> <p>Un initialized variables declared with the "static" keyword are initialized to zero. Such variables are implicitly initialized to the null pointer if they are pointers, and to 0.0F if they are floating point numbers. <br />Local variables start out containing garbage, unless they are explicitly initialized. <br />Memory obtained with malloc() and realloc() is likely to contain junk, and must be initialized. Memory obtained with calloc() is all-bits-0, but this is not necessarily useful for pointer or floating-point values (This is in contrast to Global pointers and Global floating point numbers, which start as zeroes of the right type). </p> </li> <li><strong>Does C have boolean variable type?</strong> <p>No, C does not have a boolean variable type. One can use ints, chars, #defines or enums to achieve the same in C. <br /><code> <br />#define TRUE 1  <br />#define FALSE 0  <br />enum bool {false, true}; <br /></code> <br />An enum may be good if the debugger shows the names of enum constants when examining variables.</p> </li> <li><strong>Where may variables be defined in C?</strong> <p>Outside a function definition (global scope, from the point of definition downward in the source code). Inside a block before any statements other than variable declarations (local scope with respect to the block).</p> </li> <li><strong>To what does the term storage class refer? What are auto, static, extern, volatile, const classes?</strong> <p>This is a part of a variable declaration that tells the compiler how to interpret the variable's symbol. It does not in itself allocate storage, but it usually tells the compiler how the variable should be stored. Storage class specifiers help you to specify the type of storage used for data objects. Only one storage class specifier is permitted in a declaration this makes sense, as there is only one way of storing things and if you omit the storage class specifier in a declaration, a default is chosen. The default depends on whether the declaration is made outside a function (external declarations) or inside a function (internal declarations). For external declarations the default storage class specifier will be extern and for internal declarations it will be auto. The only exception to this rule is the declaration of functions, whose default storage class specifier is always extern. <br />Here are C's storage classes and what they signify:</p> <ul> <li>auto - local variables. </li> <li>static - variables are defined in a nonvolatile region of memory such that they retain their contents though out the program's execution. </li> <li>register - asks the compiler to devote a processor register to this variable in order to speed the program's execution. The compiler may not comply and the variable looses it contents and identity when the function it which it is defined terminates. </li> <li>extern - tells the compiler that the variable is defined in another module. </li> </ul> <br />In C, const and volatile are type qualifiers. The const and volatile type qualifiers are completely independent. A common misconception is to imagine that somehow const is the opposite of volatile and vice versa. This is wrong. The keywords const and volatile can be applied to any declaration, including those of structures, unions, enumerated types or typedef names. Applying them to a declaration is called qualifying the declaration?that's why const and volatile are called type qualifiers, rather than type specifiers. <ul> <li>const means that something is not modifiable, so a data object that is declared with const as a part of its type specification must not be assigned to in any way during the run of a program. The main intention of introducing const objects was to allow them to be put into read-only store, and to permit compilers to do extra consistency checking in a program. Unless you defeat the intent by doing naughty things with pointers, a compiler is able to check that const objects are not modified explicitly by the user. It is very likely that the definition of the object will contain an initializer (otherwise, since you can't assign to it, how would it ever get a value?), but this is not always the case. For example, if you were accessing a hardware port at a fixed memory address and promised only to read from it, then it would be declared to be const but not initialized. </li> <li>volatile tells the compiler that other programs will be modifying this variable in addition to the program being compiled. For example, an I/O device might need write directly into a program or data space. Meanwhile, the program itself may never directly access the memory area in question. In such a case, we would not want the compiler to optimize-out this data area that never seems to be used by the program, yet must exist for the program to function correctly in a larger context. It tells the compiler that the object is subject to sudden change for reasons which cannot be predicted from a study of the program itself, and forces every reference to such an object to be a genuine reference. </li> <li>const volatile - Both constant and volatile. </li> </ul> <br />The "volatile" modifier <br />The volatile modifier is a directive to the compiler?s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the volatile modifier is desirable. The first case involves memory-mapped hardware (a device such as a graphics adaptor that appears to the computer?s hardware as if it were part of the computer?s memory), and the second involves shared memory (memory used by two or more programs running simultaneously). Most computers have a set of registers that can be accessed faster than the computer?s main memory. A good compiler will perform a kind of optimization called ?redundant load and store removal.? The compiler looks for places in the code where it can either remove an instruction to load data from memory because the value is already in a register, or remove an instruction to store data to memory because the value can stay in a register until it is changed again anyway. <br />If a variable is a pointer to something other than normal memory, such as memory-mapped ports on a <br />peripheral, redundant load and store optimizations might be detrimental. For instance, here?s a piece of code that might be used to time some operation: <br /><code> <br />time_t time_addition(volatile const struct timer *t, int a)  <br />{  <br />  int n;  <br />  int x;  <br />  time_t then;  <br />  x = 0;  <br />  then = t->value;  <br />  for (n = 0; n < 1000; n++)  <br />  {  <br />    x = x + a;  <br />  }  <br />  return t->value - then;  <br />}  <br /></code> <br />In this code, the variable t->value is actually a hardware counter that is being incremented as time passes. The function adds the value of a to x 1000 times, and it returns the amount the timer was incremented by while the 1000 additions were being performed. Without the volatile modifier, a clever optimizer might assume that the value of t does not change during the execution of the function, because there is no statement that explicitly changes it. In that case, there?s no need to read it from memory a second time and subtract it, because the answer will always be 0. The compiler might therefore ?optimize? the function by making it always return 0. If a variable points to data in shared memory, you also don?t want the compiler to perform redundant load and store optimizations. Shared memory is normally used to enable two programs to communicate with each other by having one program store data in the shared portion of memory and the other program read the same portion of memory. If the compiler optimizes away a load or store of shared memory, communication between the two programs will be affected. </li> <li><strong>What does the typedef keyword do?</strong> <p>This keyword provides a short-hand way to write variable declarations. It is not a true data typing mechanism, rather, it is syntactic "sugar coating". <br />For example <br /><code> <br />typedef struct node <br />{ <br />  int value; <br />  struct node *next; <br />}mynode; <br /></code> <br />This can later be used to declare variables like this <br /><code> <br />mynode *ptr1; <br />and not by the lengthy expression <br />struct node *ptr1; <br /></code> <br />There are three main reasons for using typedefs:</p> <ul> <li>It makes the writing of complicated declarations a lot easier. This helps in eliminating a lot of clutter in the code. </li> <li>It helps in achieving portability in programs. That is, if we use typedefs for data types that are machine dependent, only the typedefs need to change when the program is ported to a new platform. </li> <li>It helps in providing better documentation for a program. For example, a node of a doubly linked list is better understood as ptrToList than just a pointer to a complicated structure. </li> </ul> </li> <li><strong>What is the difference between constants defined through #define and the constant keyword?</strong> <p>A constant is similar to a variable in the sense that it represents a memory location (or simply, a value). It is different from a normal variable, in that it cannot change it's value in the proram - it must stay for ever stay constant. In general, constants are a useful because they can prevent program bugs and logical errors(errors are explained later). Unintended modifications are prevented from occurring. The compiler will catch attempts to reassign new values to constants. <br />Constants may be defined using the preprocessor directive #define. They may also be defined using the const keyword. <br />So whats the difference between these two? <br /><code> <br />#define ABC 5 <br />and <br />const int abc = 5; <br /></code> <br />There are two main advantages of the second one over the first technique. First, the type of the constant is defined. "pi" is float. This allows for some type checking by the compiler. Second, these constants are variables with a definite scope. The scope of a variable relates to parts of your program in which it is defined. <br />There is also one good use of the important use of the const keyword. Suppose you want to make use of some structure data in some function. You will pass a pointer to that structure as argument to that function. But to make sure that your structure is readonly inside the function you can declare the structure argument as const in function prototype. This will prevent any accidental modification of the structure values inside the function. </p> </li> <li><strong>What are Trigraph characters?</strong> <p>These are used when you keyboard does not support some special characters <br /><code> <br />    ??=    # <br />    ??(    [ <br />    ??)    ] <br />    ??<    { <br />    ??>    } <br />    ??!    | <br />    ??/    \ <br />    ??'    ^ <br />    ??-    ~ <br /></code></p> </li> <li><strong>How are floating point numbers stored? Whats the IEEE format?</strong> <p>IEEE Standard 754 floating point is the most common representation today for real numbers on computers, including Intel-based PC's, Macintoshes, and most Unix platforms. <br />IEEE floating point numbers have three basic components: the sign, the exponent, and the mantissa. The mantissa is composed of the fraction and an implicit leading digit (explained below). The exponent base(2) is implicit and need not be stored. <br />The following figure shows the layout for single (32-bit) and double (64-bit) precision floating-point values. The number of bits for each field are shown (bit ranges are in square brackets): <br /><code> <br />                 Sign   Exponent   Fraction   Bias  <br />-------------------------------------------------- <br />Single Precision 1 [31] 8 [30-23]  23 [22-00] 127  <br />Double Precision 1 [63] 11 [62-52] 52 [51-00] 1023  <br /></code> <br />The sign bit is as simple as it gets. 0 denotes a positive number; 1 denotes a negative number. Flipping the value of this bit flips the sign of the number. <br />The exponent field needs to represent both positive and negative exponents. To do this, a bias is added to the actual exponent in order to get the stored exponent. For IEEE single-precision floats, this value is 127. Thus, an exponent of zero means that 127 is stored in the exponent field. A stored value of 200 indicates an exponent of (200-127), or 73. For reasons discussed later, exponents of -127 (all 0s) and +128 (all 1s) are reserved for special numbers. For double precision, the exponent field is 11 bits, and has a bias of 1023. <br />The mantissa, also known as the significand, represents the precision bits of the number. It is composed of an implicit leading bit and the fraction bits. To find out the value of the implicit leading bit, consider that any number can be expressed in scientific notation in many different ways. For example, the number five can be represented as any of these: <br /><code> <br />        5.00 × 100 <br />        0.05 × 10 ^ 2 <br />        5000 × 10 ^ -3 <br /></code> <br />In order to maximize the quantity of representable numbers, floating-point numbers are typically stored in normalized form. This basically puts the radix point after the first non-zero digit. In normalized form, five is represented as 5.0 × 100. A nice little optimization is available to us in base two, since the only possible non-zero digit is 1. Thus, we can just assume a leading digit of 1, and don't need to represent it explicitly. As a result, the mantissa has effectively 24 bits of resolution, by way of 23 fraction bits. <br />So, to sum up: <br /><code> <br />1. The sign bit is 0 for positive, 1 for negative.  <br />2. The exponent's base is two.  <br />3. The exponent field contains 127 plus the true exponent for single-precision,  <br />   or 1023 plus the true exponent for double precision.  <br />4. The first bit of the mantissa is typically assumed to be 1.f, where f is the  <br />   field of fraction bits.  <br /></code></p> </li> <li><strong>When should the register modifier be used?</strong> <p>The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU?s registers, if possible, so that it can be accessed faster. There are several restrictions on the use of the register modifier. <br />First, the variable must be of a type that can be held in the CPU?s register. This usually means a single value of a size less than or equal to the size of an integer. Some machines have registers that can hold floating-point numbers as well. Second, because the variable might not be stored in memory, its address cannot be taken with the unary & operator. An attempt to do so is flagged as an error by the compiler. Some additional rules affect how useful the register modifier is. Because the number of registers is limited, and because some registers can hold only certain types of data (such as pointers or floating-point numbers), the number and types of register modifiers that will actually have any effect are dependent on what machine the program will run on. Any additional register modifiers are silently ignored by the compiler. Also, in some cases, it might actually be slower to keep a variable in a register because that register then becomes unavailable for other purposes or because the variable isn?t used enough to justify the overhead of loading and storing it. So when should the register modifier be used? The answer is never, with most modern compilers. Early C compilers did not keep any variables in registers unless directed to do so, and the register modifier was a valuable addition to the language. C compiler design has advanced to the point, however, where the compiler will usually make better decisions than the programmer about which variables should be stored in registers. In fact, many compilers actually ignore the register modifier, which is perfectly legal, because it is only a hint and not a directive. </p> </li> <li><strong>When should a type cast be used?</strong> <p>There are two situations in which to use a type cast. <br />The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly. <br />The second case is to cast pointer types to and from void * in order to interface with functions that expect or return void pointers. For example, the following line type casts the return value of the call to malloc() to be a pointer to a foo structure. <br /><code> <br />struct foo *p = (struct foo *) malloc(sizeof(struct foo));  <br /></code> <br />A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer to one type of structure or data type into another. In the <br />rare events in which this action is beneficial, using a union to hold the values makes the programmer?s intentions clearer. </p> <p> <br /></p> </li> <li><strong>Can structures be assigned to variables and passed to and from functions?</strong> <p>Yes, they can! <br />But note that when structures are passed, returned or assigned, the copying is done only at one level (The data pointed to by any pointer fields is not copied!. </p> <p> <br />These Questions are taken from CrackTheInterview team.</p> </li> </ol> 13kchaitanyya@gmail.com (chaitanya)