Você está na página 1de 8

Section 1 - some aptitude question + predicting output of a given program + some conceptual question(mainly in OS) Section 2- programming section...

there were three questions 1)given two sorted linked list u have to return the linked list which is the merged list of the first two and also is sorted. 2)given two Binary trees, u have to find whether the second is a sub tre e of the first... 3)Given an array which contains integers(may contain thousands of elemen ts), u have to write a program to find the second largest element of the group.. .. the first two u can run (i.e) u can check the output....but the t hird u have to just write the code and u cant check the output....

Paper was of 2 hrs. with 10 MCQs and 5 programming questions. 1. Find repeating characters in the string and print them in lexicographical ord er. eg- aaabccffd ans- acf 2. Delete Kth node from a linked list. 3. Rotate the given matrix by 90 degree. 4.Clone a directed graph. 5.Write functions to find whether 2 timerange overlap or are within range. Amazon online test question paper 2011 We had an online test which had 22 questions including 2 coding and 20 MCQs. Here are a few questions I remember.: 1)write code to find sum of two numbers stored as linked list.(LSB at last node) and head of each list is given. 2)write code to print elements on the path from root to leaf node having the ma ximum sum. MCQ: 3)what is the complexity of retrieving min element from a max heap. 4)which is the fastet method to sort an almost sorted array: quick sort,bubble sort,merge sort,shell sort 5)zombie process 6)hash table 7)reverse linked list and a few questions on tress and dynamic prog and aptitude testing.

diameter of tree, 2. write routing problem: ie finding the shortest path for the rat to cheese in a maze Apti Round: 20 aptitude questions. it was simple.. around 4 to 5 general aptitude ques.. 4 to5 find the o/p ques..

some on n/wing C Questions for Outrput: 1. int a[]={1,2,3,4,5}; int *ptr=a; print((&ptr)-1); 2. base addr+((size of int)*size of arr)-size of int

Multiple Choice,Amazon online test: 1)Given two sorted arrays of size m and n each, what is the minimum time taken t o find the kth smallest element in the combined array 2)what is Minimum number of edges in a connected graph N nodes 3)What is the minimum number of using the next pointer required to find median o f a sorted singly linked list of size n 4) #include<stdio.h> int findKthsmallest(int a[],int m,int b[],int n,int k) { int i=0,j=0,ti=0,tj=0,I=0,J=0,M=m,N=n; while(1) { ti = (int)((double)m/(m+n) * (k-1)); tj = (k-1)-ti; i = I+ti; j= J+tj; //printf(" i=%d j=%d\n",i,j); if(j>0 && j<N && i<M && a[i]>b[j-1] && a[i]<b[j]) return a[i]; if(i>0 && i<M && j<N && b[j]>a[i-1] && b[j]<a[i]) return b[j]; if(j==0 && i<M && a[i]<b[j]) return a[i]; if(i==0 && j<N && b[j]<a[i]) return b[j]; if(j==N && a[i]>b[j-1]) return a[i]; if(i==M && b[j]>a[i-1]) return b[j]; if(i<M && j<N) { if(a[i]<b[j]) { k=k-ti-1; m=m-ti-1; I=i+1; }

else { k=k-tj-1; n=n-tj-1; J=j+1; } } else if(i>=M) { k=k-tj-1; n=n-tj-1; J=j+1; } else { k=k-ti-1; m=m-ti-1; I=i+1; } } } int main() { int a[]={1,2,3}; int b[]={4}; int m=3,n=1,k=3; printf("%d",findKthsmallest(a,m,b,n,k)); return 0; } - ananthakrishnan.s.r on June 16, 2011 Edit Hi can you please explain your code?? I wanted to crack this code for a long tim e now. and found one solution.. Please comments your code.. It would be helpful. . Thanks. - Algorist on June 17, 2011 Edit Idea is like this since both the arrays may not be of same length lets divide (k -1) smallest elements proportionally in both the arrays: let i point the array A by i=m/(m+n) * (k-1) [since we have to divide k-1 elements among two] j=(k-1) - i then try to insert A[i] between B[j-1] and B[j] if three are not in asc order tr y to insert B[j] between A[i-1] and A[i] If any one of the above satisfies we found kth smallest element else, check which one is smallest among A[i] and B[j] its logical that if A[i] is smal lest then we can A[0] to A[i] for the next iteration and k becomes k-i-1 also m becomes m-i-1 i.e now we have only m-i-1+n elements out o f which we have to find k-i-1th smallest thus the iteration goes on until we find our kth smallest element. Consider 2 arrays

A={5,7,9,20}; length of A: m=4 B={10,12,21,27,35,50}; length of B: n=6 let K be 4 i=4/10*3=1; A[1]=7; j=3-1=2; B[2]=21; B[1]=12 A[1]=7 B[2]=21 [not in asc order] A[0]=5 B[2]=21 A[1]=7 [not in asc order] so now, k=k-i-1 =4-1-1=2 m=m-i-1=4-1-1=2 n=6 A={9,20}; length of A: m=2 B={10,12,21,27,35,50}; length of B: n=6 i=2/8*1=0; A[0]=9; j=1-0=1; B[1]=12; (acutally A[-1] is just for understanding) B[0]=10 A[0]=9 B[1]=12 [not in asc order] A[-1]=-INF B[1]=12 A[0]=9 [not in asc order] now, k=k-i-1=2-0-1=1; m=m-i-1=2-0-1=1; n=6; A={20}; length of A: m=1 B={10,12,21,27,35,50}; length of B: n=6 i=1/7*0=0; A[0]=20; j=0-0=0; B[0]=10; (acutally A[-1] and B[-1] are just for understanding) B[-1]=-INF A[0]=20 B[0]=10 [not in asc order] A[-1]=-INF B[0]=10 A[0]=20 [in asc order] We got the Kth(4th) smallest element which is 10.

Amazon interview questions By admin | June 16, 2008

1. Given a Binary Search Tree, write a program to print the kth smallest elem ent without using any static/global variable. You can t pass the value k to any functi also. 2. What are the 4 basics of OOP? 3. Define Data Abstraction. What is its importance? 4. Given an array of size n. It contains numbers in the range 1 to n. Each nu mber is present at least once except for 2 numbers. Find the missing numbers. 5. Given an array of size n. It contains numbers in the range 1 to n. Find th e numbers which aren t present. 6. Given a string,find the first un-repeated character in it? Give some test cases 7. You are given a dictionary of all valid words. You have the following 3 op erations permitted on a word: delete a character, insert a character, replace a character. Now given two words - word1 and word2 - find the minimum number of st eps required to convert word1 to word2. (one operation counts as 1 step.) 8. Given a cube of size n*n*n (i.e made up of n^3 smaller cubes), find the nu mber of smaller cubes on the surface. Extend this to k-dimension. 9. What is a C array and illustrate the how is it different from a list. 10. What is the time and space complexities of merge sort and when is it prefe rred over quick sort? 11. Write a function which takes as parameters one regular expression(only ? a nd * are the special characters) and a string and returns whether the string mat ched the regular expression. 12. Given n red balls and m blue balls and some containers, how would you dist ribute those balls among the containers such that the probability of picking a r ed ball is maximized, assuming that the user randomly chooses a container and th en randomly picks a ball from that. 13. 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 s ame. 14. Given an array of size n, containing every element from 1 to n+1, except o ne. Find the missing element. 15. How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same 16. Explain polymorphism. Provide an example. 17. Given an array all of whose elements are positive numbers, find the maximu m sum of a subsequence with the constraint that no 2 numbers in the sequence sho uld be adjacent in the array. So 3 2 7 10 should return 13 (sum of 3 and 10) or 3 2 5 10 7 should return 15 (sum of 3, 5 and 7) 18. You are given some denominations of coins in an array (int denom[])and inf inite supply of all of them. Given an amount (int amount), find the minimum numb er of coins required to get the exact amount. What is the method called? 19. Given an array of size n. It contains numbers in the range 1 to n. Each nu mber is present at least once except for 1 number. Find the missing number.

1. Write a function isValid(int sudoko[][]) to chec whether a given sudoko solut ion is valid or not. 2. You are given a paragraph in which the length of all the words in a line has following properties: odd position words are in increasing order of their length even position words are in decreasing order of their length you are given a word, you have to write a code to search it in the given paragra ph and return the line

1. Find an element in the array following the condition a[i] =i. int arr[] = {0,1,3,5} output = 0 0r 1 2. Find out elements which is not duplicate in the given array. Int arr[] = {1,3,5,7,1,3,5} Output = 7 3.write a function that returns the element which is having maximum occourance i n the given string Char input_str [] = "the things are thin" So it will returns "t" as it's occourance is 3 times. 4. Algorithm 5. How to rename all the files at the given directory from .jpg to .jpeg. 6. Write a script which reverse the given string x = "the pen is mine" the outpu t is mine is pen the. 7. I want to delete a file in 1000 hosts.1000 host names are provided. 8. Copy a a file form one host "amazon.chennai" to another host "anazon.bbsr" 9. Print the line from 20 to 30th of a file. 10. Forgot

1. Two tables emp (empid, name, deptid, sal) and dept(deptid, deptname) are ther e. Write a query which displays empname, corresponding deptname also display tho se employee names who do not belong to any dept. 2. Display the employees whose salary is less than average salary. 3. What is the output of the program main() { int c=5; printf("%d %d %d",c,c<<2,c>> 2); } 4. main() { int a[8][10],c=0,i,j; for(i=0;i<10; i++) for(j=0; j<8;j++) a[j][i]=c++; printf("%d",a[3][6]);

} 5.What is the wrong in this program main() { char *p,*q; p=(char *)malloc(25); q=(char*) malloc(25); strcpy(p,"amazon" ); strcpy(q,"hyd"); strcat(p,q); printf("%s",p); } 6. Write prefix and post fix notation for (a+b)*c-(d+e)^(f-g) 7. What is the output of the program main() { int i=5; printf("%d",fun(fun(fun(fun( fun(i)))))); } void fun (int i) { if(i%2) return (i+(7*4)-(5/2)+(2*2)); else return (i+(17/5)-(34/15)+(5/2)); } 8. When it is always true boolean fun (node *p) { return ((p==null)||(p->next==null)|| (p->info<=p->next->info)&&( fun(p->next))); } a) when list is empty or has one node b) when the ele are sorted in non decreasing order c) when the ele are sorted in non increasing order 9. a) b) c) What x is x is x is is x here (x&&!(x&(x-1))==1) always a prime a power of 2 even d)x is odd

10. What is the difference between deep copy and shallow copy 11. In java what is the difference between sleep() and wait(). 12. What happens when the parent process of a child process exits before the chi ld ? 13. There are three persons A, B, C. A shots the target 6 times out of 7 shots. B shots 4 out of 5 shots. Then what is the probability of hitting the target twi ce when 2 persons are selected at random. 14. What is valid in cpp char *cp; const char *cpp; 1) cpp=cp; 2) cp=cpp; 15. Write program to swap 2 variables without using extra memory. 16. Write a shell command to find all Java files present in nested directories. 17. There are 6 pairs of black socks and 6 pairs of white socks. What is the pro bability to pick a pair of black or white socks when 2 socks are selected random

ly in darkness. 18. A string of alphanumeric is there. Find a string that starts with b and ends with 3 characters. Section B (we have to write programs) time:30 min 1. There is a sorted array which is of very large size. In that all except one n o. are repeated once. How to find that non repeated no. 2. There are 2 linked lists. Those 2 lists are meeting at a point. How to find t hat meeting point.