Sunday, March 6, 2016

Amazon Whole Test Paper

Amazon Whole Test Paper
  Amazon Placement paper

1. Two tables emp(empid,name,deptid,sal) and dept(deptid,deptname) are there.write a query which displays empname,corresponding deptname also display those employee names who donot belong to any dept.
2. Write prefix and post fix notation for (a+b)*c-(d+e)^(f-g)
3. write program to swap 2 variables without using extra memory.
4. Find the output for the following C program fn f(x)
{
if(x<=0)
return;
else f(x-1)+x;
}
5. Find the output for the following C program main()
{
   intx=2,y=6,z=6;
   x=y=z;
   printf(%d",x)
}
6. Copy a a file form one host "amazon.chennai" to another host "anazon.bbsr"
7. You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.?
public class MyAr{
public static void main(String argv[]){
int[] i = new int[5];
System.out.println(i[5]);
}
}
1) An error at compile time
2) An error at run time
3) The value 0 will be output
4) The string "null" will be output.
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.
9. Write a program to remove duplicates from a sorted array.
10. In C, if you pass an array as an argument to a function, what actually gets passed?
A.  Value of elements in array
B.  First element of the array
C.  Base address of the array
D.  Address of the last element of array
Ans-C


11. What will be the output of the program ?


A.  2, 3, 4, 5 B.  1, 2, 3, 4
C.  0, 1, 2, 3 D.  3, 2, 1 0
Ans-B

12. What will be the output of the program if the array begins 1200 in memory?
A.  1200, 1202, 1204 B.  1200, 1200, 1200
C.  1200, 1204, 1208 D.  1200, 1202, 1200
Ans-B
13. Which of the following statements are correct about an array?
1:  The array int num[26]; can store 26 elements.
2:  The expression num[1] designates the very first element in the array.
3:  It is necessary to initialize the array at the time of declaration.
4:  The declaration num[SIZE] is allowed if SIZE is a macro.
A.  1   B.  1,4
C.  2,3   D.  2,4
Ans-B
14. Which of the following function is used to find the first occurrence of a given string in another string?
A.  strchr()   B.  strrchr()
C.  strstr()   D.  strnset()
Ans-C
15. Which of the following function is correct that finds the length of a string?
Ans-A
16. What will be the output of the program in 16-bit platform (Turbo C under DOS) ?
A.  8, 1, 4    B.  4, 2, 8
C.  4, 2, 4    D.  10, 3, 4
Ans-B
17. Which of the following statements are correct ?
1:  A string is a collection of characters terminated by '\0'.
2:  The format specifier %s is used to print a string.
3:  The length of the string can be obtained by strlen().
4:  The pointer CANNOT work on string.
A.  A, B   B.  A, B, C
C.  B, D   D.  C, D
Ans-B
18. What is the wrong in this program
19. Point out the error in the program?
A.  Error: invalid structure member
B.  Error: Floating point formats not linked
C.  No error
D.  None of above
Ans-B
20. What is the similarity between a structure, union and enumeration?
A.  All of them let you define new values
B.  All of them let you define new data types
C.  All of them let you define new pointers
D.  All of them let you define new structures
Ans-B
21. What will be the output of the program ?
#include<stdio.h>
int main()
{
    enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
    printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);
    return 0;
}
A. -1, 0, 1, 2, 3, 4   B. -1, 2, 6, 3, 4, 5
C. -1, 0, 6, 2, 3, 4   D. -1, 0, 6, 7, 8, 9
Ans-D
22. What will be the output of the program ?
A. 103 Dotnet    B. 102 Java
C. 103 PHP    D. 104 DotNet
Ans-A
23. In which stage the following code
#include<stdio.h>
gets replaced by the contents of the file stdio.h
A.  During editing   B. During linking
C.  During execution  D. During preprocessing
Ans-D
24. Point out the error in the program
A.  Error: unexpected end of file because there is no matching #endif
B.  The number is odd
C.  Garbage values
D.  None of above
Ans-A
25. What are the different types of real data type in C ?
A. float, double    B. short int, double, long int
C. float, double, long double  D. double, long int, float
Ans-C
26. Which statement will you add in the following program to work it correctly?
A.  #include<conio.h> B.  #include<math.h>
C.  #include<stdlib.h> D.  #include<dos.h>
Ans-B
27. What do the following declaration signify?
int *ptr[30];
A.  ptr is a pointer to an array of 30 integer pointers.
B.  ptr is a array of 30 pointers to integers.
C.  ptr is a array of 30 integer pointers.
D.  ptr is a array 30 pointers.
Ans-B
28. What is x in the following program?
A.  x is a pointer
B.  x is an array of three pointer
C.  x is an array of three function pointers
D.  Error in x declaration
Ans-C
29. In the following code snippet can we declare a new typedef named ptr even though struct employee has not been completely declared while using typedef?
A. Yes    B. No
Ans-A
30. What will be the output of the program?
A.  3, 4, 4, 3 B.  4, 3, 4, 3
C.  3, 3, 4, 4 D.  3, 4, 3, 4
Ans-B
APTITUDE
Predict the output or error(s) for the following:
1.
2.
3.


4
5.


  2. What are the files which are automatically opened when a C file is executed?
  3. what will be the position of the file marker?
            a: fseek(ptr,0,SEEK_SET);
            b: fseek(ptr,0,SEEK_CUR);
  4. What is the problem with the following code segment?
            while ((fgets(receiving array,50,file_ptr)) != EOF)
  5. Predict the output or error(s)

  
  6. Predict the output or error(s)

  
7. In the following pgm add a  stmt in the function  fun such that the address of
    'a' gets stored in 'j'.


Ans- *k = &a
8. What are the following notations of defining functions known as?

Ans
   i.  ANSI C notation
  ii. Kernighan & Ritche notation
9. Is the following statement a declaration/definition. Find what does it mean?
  int (*x)[10];
Ans- Definition-x is a pointer to array of(size 10) integers.
10. . What is the output for the program given below

     typedef enum errorType{warning, error, exception,}error;
     main()
    {
        error g1;
        g1=1;
        printf("%d",g1);
     }
 
Ans- Compiler error: Multiple declaration for error
11. What is the output for the program given below
   typedef struct error{int warning, error, exception;}error;
     main()
    {
        error g1;
        g1.error =1;
        printf("%d",g1.error);
     }
Ans-1
12. What is the output for the program given below

Ans-bye
13. What is the output for the program given below


Ans-                              1       1       1       1
                                    2       4       2       4
                                    3       7       3       7
                                    4       2       4       2
                                    5       5       5       5
                                    6       8       6       8
                                    7       3       7       3
                                    8       6       8       6
                                    9       9       9       9
14. Declare an array of N pointers to functions returning pointers to functions             returning pointers to characters?
Ans- (char*(*)( )) (*ptr[N])( );
15. There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong?
16. Is there any difference between the two declarations,
1.      int foo(int *arr[]) and
2.      int foo(int *arr[2])
Ans-No
17. What is the subtle error in the following code segment?
18. What is wrong with the following code?
19. What is the hidden bug with the following  statement?
  assert(val++ != 0);
20. Is the following code legal?
struct a
    {
int x;
struct a b;
    }
Ans-No
21. Is the following code legal?
void main()
{
typedef struct a aType;
aType someVariable;
struct a
{
int x;
      aType *b;
              };
}
Ans-no
22. Which version do you prefer of the following two,
1) printf(“%s”,str);      // or the more curt one
2) printf(str);
Ans-1
23. Find the output.
  main()
{        
char a[4]="HELL";
printf("%s",a);
}
Ans- HELL%@!~@!@???@~~!
24. Printf can be implemented by using  __________ list.
Ans-Verbal Length argument
25. The command which gives the  device of our system
Ans-Who
26. Which of following is correct:
a)For loops can be nested
b)For Loops may use the same Index
c)For loops cannot be overllapped
Ans:a,c

27. when the system starts which will execute?
Ans- Booting loader

28. ada is _____________ language
      a)modular b)object based c)object oriented d)functional

29. The maximum level of the tree is
Ans-depth of the tree

30. which is used for storing pictures or graphics
a) mbr  b)mar  c)frame buffer  d)sdram

Saturday, March 5, 2016

Number Series

Number Series

Generally, two kinds of series are asked in the examination.  One is based on numbers and the other based on alphabets.

In questions based on series, some numbers or alphabets are arranged in a particular sequence. You have to decipher that particular sequence of numbers or alphabets and on the basis of that deciphered sequence, find out the next number or alphabet of the series. Although there is no limit of logics which can be used to build a series, here are some important examples given which highlight the type of series asked in the examination.

How to solve number series problems:

Step 1: Observer are there any familier numbers in the given series.  Familier numbers are primes numbers, perfect squares, cubes ... which are easy to identify.
Step 2: Calculate the differences between the numbers.  Observe the pattern in the differences.  If the differences are growing rapidly it might be a square series, cube series, or multiplicative series.  If the numbers are growing slowly it is an addition or substration series.

If the differences are not having any pattern then
1.  It might be a double or triple series.  Here every alternate number or every 3rd number form a series
2.  It might be a sum or average series.  Here sum of two consecutive numbers gives 3rd number.  or average of first two numbers give next number
         
Step 3: Sometimes number will be multiplied and will be added another number So we need to check those patterns

TYPES :

I. Prime number Series :
  Example (1) : 2,3,5,7,11,13, ...........
 Answer : The given series is prime number series . The next prime number is 17.

 Example (2) :2,5,11,17,23,...........41.
 Answer: The prime numbers are written alternately.

II. Difference Series : Example (1): 2,5,8,11,14,17,...........,23.
 Answer: The difference between the numbers is 3. (17+3 = 20)
Example (2): 45,38,31,24,17,...........,3.
Answer: The difference between the numbers is 7. (17-7=10).

III. Multiplication Series: Example (1) : 2,6,18,54,162,.........,1458.
Answer: The numbers are multiplied by 3 to get next number. (162x3 = 486).

 Example: (2) : 3,12,48,192,............,3072.
Answer : The numbers are multiplied by 4 to get the next number. (192x4 =768).

IV.  Division Series:
Example (1): 720, 120, 24, .........,2,1
Answer: 720/6=120, 120/5=24, 24/4=6, 6/3=2, 2/2=1.

Example (2) : 32, 48, 72, 108, .........., 243.
Answer: 2. Number x 3/2= next number. 32x3/2=48, 48x3/2=72, 72x3/2=108,
 108x3/2=162.

V. n2 Series:
Example(1) : 1, 4, 9, 16, 25, ......., 49
Answer:  The series is 12, 22, 32, 42, 52, .... The next number is 62=36;

 Example (2) : 0, 4, 16, 36, 64, ........ 144.
Answer :The series is 02, 22, 42, 62, etc. The next number is 102=100.

VI.  n21 Series :
Example : 0, 3, 8, 15, 24,35, 48, ..........,
 Answer : The series is 12-1, 22-1, 32-1 etc. The next number is 82-1=63.
 Another logic : Difference between numbers is 3, 5, 7, 9, 11, 13 etc. The next number is (48+15=63).

VII.n2+1 Series : 
Example : 2, 5, 10, 17, 26, 37, .........., 65.
Answer : The series is 12+1, 22+1, 32+1 etc. The next number is 72+1=50.

VIII. n2+n Series (or)n2n Series :
 Example : 2, 6, 12, 20, ............, 42.
 Answer : The series is 12+1, 22+2, 32+3, 42+4 etc. The next number = 52+5=30.
 Another Logic : The series is 1x2, 2x3, 3x4, 4x5, The next number is 5x6=30.
 Another Logic : The series is 22-2, 32-3, 42-4, 52-5, The next number is 62-6=30.

IX. n3 Series :
 Example : 1, 8, 27, 64, 125, 216, ......... .
 Answer : The series is 13, 23, 33, etc. The missing number is 73=343.

X. n3+n Series : 
Example : 2, 9, 28, 65, 126, 217, 344, ...........
 Answer : The series is 13+1, 23+1, 33+1, etc. The missing number is 83+1=513.

XI. n31 Series :
Example : 0, 7, 26, 63, 124, ............, 342.
Answer:The series is 13-1, 23-1, 33-1 etc The missing number is 63-1=215.

XII. n3+n Series :
 Example : 2, 10, 30, 68, 130, .............., 350.
 Answer : The series is 13+1, 23+2, 33+3 etc The missing number is 63+6=222.

XIII. n3n Series :
 Example :0, 6, 24, 60, 120, 210, ..............,
 Answer : The series is 13-1, 23-2, 33-3, etc. The missing number is 73-7=336.
 Another Logic : The series is 0x1x2, 1x2x3, 2x3x4, etc. The missing number is 6x7x8=336.

XIV. n3+n2 Series :
 Example : 2, 12, 36, 80, 150, ............,
 Answer: The series is 13+12,23+22,33+32etc. The missing number is 63+62=252

XV. n3n2 Series:
 Example: 0,4,18,48,100,.................,
 Answer :  The series is 13-12,23-22,33-32 etc. The missing number is 63-62=180

XVI. xy, x+y Series:
Example: 48,12,76,13,54,9,32,...............,
 Answer :2.  4+8=12, 7+6=13, 5+4=9   .: 3+2=5.

XVII. Image Series or (Interchange Series):
Example : 34, 81, 72, 47, 74, 27, 18, ................
 Answer :  (47,74,), (72,27), (81,18), are images.   :. Image of 34 is 43.

Google Interview Questions

Google Interview Questions
First phone interview was specific questions on what you do at work.

Second phone interview was job situational

Given a dictionary segment, a piece of un-spaced text is used to find meaningful words from it. e.g "makemytrip"-> make my trip

2nd Round :
A design question (don't remember) and another question on adversarial mini-max search

3rd Round :
Write a method to find the next ancestor of a node in a Binary Search Tree.
Write a recursive function to convert Binary Code of a number into its equivalent Gray's code and the other way round.

4th round:
Given two sorted arrays, find the kth minimum element of both.
Given a set of intervals, find the interval which has the maximum number of intersections.

5th round:
This one was focused on previous projects and experience and how good I was at what I had been doing.
Questions asked in different streams

1. Tell me about a situation when you had to multitask.

2. Why do you want to choose Google?

3. Describe a time when you had to tell a client that you couldn't meet a deadline
.
4. What was the best part you did on the role play?

5. What do you do in your spare time/when not working?

6. Given a list of integers that fall within a known short but unknown range of values, how to find the median value?

7. Out of 10 coins, one weighs less than the others. You have a scale.

    How can you determine which one weighs less in 3 weighs?

    Now how would you do it if you didn't know if the odd coin weighs less or more?

8. Code an application that creates a new thread and exposes a "ping()" method. Whenever ping() is

9. called, the thread prints "Google rocks" once.

10. Write a method to pretty print a binary tree. Don't make any assumptions, i.e. the tree could be highly unbalanced.

11. Given a list of integers that fall within a known short but unknown range of values, how to find the median value?

12. Convert char string to integer.

13. Write a method to pretty print a binary tree. Don't make any assumptions, i.e. the tree could be highly unbalanced.

14. Find occurrences of a number in sorted array (allow duplicates).

15. If integer array used to store big integers (one integer store one digit), implement arithmetic operations

16. In which field do you feel you have an edge?

17. To generate a fibonacci number sequence, and discuss its time and space complexity.

18. To merge two sorted integer arrays.