Monday, February 22, 2016

TCS placement questions - 2

TCS placement questions - 2

1. If f(x) = (1+x+x2+x3+.......x2012)2x2012
g(x) = 1+x+x2+x3+.......x2011 
Then what is the remainder when f(x) is divided by g(x)
Let us multiply g(x) with x on the both sides
x.g(x) = x+x2+x3+.......x2012
add 1 on both sides
x. g(x) + 1 = 1+x+x2+x3+.......x2012
Substitute this value in f(x)
then f(x) = (x.g(x)+1)2x2012
f(x) = x2.g(x)2+2.g(x)+1x2012
Now f(x) is divisible by g(x) first two terms are exactly divisible by g(x) and we get 1 - x2012
But 1 - x2012 = (1 - x)(1+x+x2+x3+.......x2011)
if this expression is divisible by g(x) we get 0 as remainder.

2. A number has exactly 3 prime factors, 125 factors of this number are perfect squares and 27 factors of this number are perfect cubes. overall how many factors does the number have?
We know that the total factors of a number N = ap.bq.cr ....
Now the total factors which are perfect squares of a number N = ([p2]+1).([q2]+1).([r2]+1)....
where [x] is greatest intezer less than that of x.
Given ([p2]+1).([q2]+1).([r2]+1).... = 125
So [p2]+1 = 5;  [q2]+1 = 5; [p2]+1 = 5
[p2] = 4  p = 8 or 9, similarly q = 8 or 9, r = 8 or 9
Given that 27 factors of this number are perfect cubes
so ([p3]+1).([q3]+1).([r3]+1).... = 27
So [p3]+1 = 3  = [p3] = 2
 p = 6, 7, 8
By combining we know that p = q = r = 8
So the given number should be in the format = a8.b8.c8 ....
Number of factors of this number = (8+1).(8+1).(8+1) = 729

3. In a class there are 60% of girls of which 25% poor.  What is the probability that a poor girl is selected is leader?
Assume total students in the class = 100
Then Girls = 60% (100) = 60
Poor girls = 25% (60) = 15
So probability that a poor girls is selected leader = Poor girls / Total students = 15/100 = 15%

4. A and B are running around a circular track of length 120 meters with speeds 12 m/s and 6 m/s in the same direction.  When will they meet for the first time?
A meets B when A covers one round more than B.
A's relative speed = (12 - 6) m/s.  So he takes 120 / 6 seconds to gain one extra round.
So after 20 seconds A meets B.

5. A completes a work in 20 days B in 60 days C in 45 days.  All three persons working together on a project got a profit of Rs.26000 what is the profit of B?
We know that profits must be shared as the ratio of their efficiencies.  But efficiencies are inversely proportional to the days.  So efficiencies of A : B : C = 1/20 : 1/60 : 1/45 = 9 : 3 : 4
So B share in the total profit = 316×26000 = Rs.4875

6. A completes a piece of work in 3/4 of the time in B does, B takes 4/5 of the time in C does.  They got a profit of Rs. 40000  how much B gets?
Assume C takes 20 Days.  Now B takes 4/5 (20) = 16 days.  A takes 3/4(16) = 12
Now their efficiencies ratio = 1/20 : 1/16 : 1/12 = 12 : 15 : 20
B's share in the profit of Rs.40000 = 15/47 (40000) = Rs.12765

7. An empty tank be filled with an inlet pipe ‘A’ in 42 minutes. After 12 minutes an outlet pipe ‘B’ is opened which can empty the tank in 30 minutes. After 6 minutes another inlet pipe ‘C’ opened into the same tank, which can fill the tank in 35 minutes and the tank is filled. Find the time taken to fill the tank?
Assume total tank capacity = 210 Liters
Now capacity of  pipe A = 210/42 = 5 Liters
Capacity of B =  210 / 30 = - 7 Liters
Capacity of C =  210 / 35 = 6 min
Assume tank gets filled in x min after the third pipe got opened.
So x×5+6×(2)+4x=210
48+4x=2104x=162x=40.5
Total time taken to fill the tank = 40.5 + 12 + 6 = 51.5

8. Mother, daughter and an infant combined age is 74, and mother's age is 46 more than daughter and infant.  If infant age is 0.4 times of daughter age, then find daughters age.
Assume M + D + I = 74; .................(1)
Also given M - D - I = 46  M = D + I + 46
Also I = 0.4 D  I = 2/5 D
Substituting M and I values in the first equation we get D - 25D - 46 + D + 25D = 74
Solving D = 10

9. A Grocer bought 24 kg coffee beans at price X per kg. After a while one third of stock got spoiled so he sold the rest for $200 per kg and made a total profit of twice the cost. What must be the price of X?
Total Cost price = 24×X
As 1/3rd of the beans spoiled, remaining beans are 2/3 (24) = 16 kgs
Selling price = 200 × 16 = 3200
Profit = Selling price - Cost price = 3200 - 24×X
Given Profit = 2 × Cost price
3200 - 24×X = 2 × (24×X)
Solving X = 44.44

10. Bhanu spends 30% of his income on petrol on scooter 20% of the remaining on house rent and the balance on food. If he spends Rs.300 on petrol then what is the expenditure on house rent?
Given 30% (Income ) = 300  Income = 1000
After having spent Rs.300 on petrol, he left with Rs.700.
His spending on house rent = 20% (700) = Rs.140

11. Let exp(m,n) = m to the power n. If exp(10, m) = n exp(2, 2) where to and n are integers then n =
Given 10m=n.22
 2m×5m=n.222m2×5m=n
For m = 2 we get least value of n = 25, and for m > 2 we get infinite values are possible for n.

12. How many kgs. of wheat costing Rs. 5 per kg must be mixed with 45 kg of rice costing Rs. 6.40 per kg so that 20% gain may be obtained by  selling the mixture at Rs. 7.20 per kg ?
If the selling price of the mixture is Rs.7.2 when sold at 20% profit then
CP ×120100 = 7.2  CP = Rs.6
Now by applying weighted average formula = K×5+45×6.4K+45=6
 K = 18 kgs

13. The diagonal of a square is twice the side of equilateral triangle then the ratio of Area of the Triangle to the Area of Square is?
Let the side of equilateral triangle = 1 unit.
We know that area of an equilateral triangle = 34a2
As side = 1 unit area of the equilateral triangle = 34
Now Diagonal of the square = 2 (side of the equilateral triangle) = 2
We know that area of the square = 12D2 where D = diagonal
So area of the square = 12(22)=2
Ratio of the areas of equilateral triangle and square = 34 : 2  3:8

14. Raj tossed 3 dices and there results are noted down then what is the probability that Raj gets 10?
Always remember when 3 dice are rolled the number of ways of getting n ( where n is the sum of faces on dice)
(n1)C2 where n = 3 to 8
= 25 where n = 9, 12
= 27 where n = 10, 11
(20n)C2 where n = 13 to 18
The required probability = 2763 = 

Sunday, February 21, 2016

Google Interview Experience | Set 2 (Placement Questions)

Google Interview Experience | Set 2 (Placement Questions)



MCQ Questions: 20 (+4, -1)
Subjective Question: 1
1) Given four matrices
P = 20×10
Q = 10×5
R = 5×10
S = 10×10
Find minimum no. of multiplication required for PxQxRxS?
a) 4000
b) 2500
c) 3000
d) None Of These
2) Two n-size arays are given . n1 in decreasing order and n2 in increasing order. If c1 is time complexity for n1 using quicksort and c2 is time complexity for n2 using quicksort. Then –
a) c1 > c2
b) c1 < c2 c) c1 = c2 d) None of these 3) If there is a N sorted array then what is time complexity of finding 2 no.s having sum less than 1000.
a) O(1)
b) O(n^2)
c) O(n)
d) O(logn)
4) There are some process . In which of the scheduling algo CPU utilization is minimum. If I/O burst time is 90ms and CPU burst time is 10ms.(question is very long to remember)
5)
int func(int x, int *y, int **z)
{
  int p, q;
  x += 2;
  p = *y++;
  q = **z++;
  q = **z++; //Not a repeated line.
}
void main()
{
  int a = 5, *b, **c;
  b = &a;
  c = &b;
  printf(“%d”,a);
}
6) Find the least significant digit of 2^3*google where google=10^100.
a) 2
b) 4
c) 6
d) 8
7) Let w(n) and A(n) denote respectively, the worst case and average case running time of an algorithm executed on an input of size n. which of the following is ALWAYS TRUE?
a) A(n) = Omega(W(n))
b) A(n) = Theta(W(n))
c) A(n) = O(W(n))
d) A(n) = o(W(n))
8) Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry Wij in the matrix W below is the weight of the edge {i, j}.
    0 1 8 1 4
    1 0 12 4 9
W = 8 12 0 7 3
    1 4 7 0 2
    4 9 3 2 0
What is the minimum possible weight of a spanning tree T in this graph such that vertex 0 is a leaf node in the tree T?
a) 7
b) 8
c) 9
d) 10
9) In the graph given in question 8, what is the minimum possible weight of a path P from vertex 1 to vertex 2 in this graph such that P contains at most 3 edges?
a) 7
b) 8
c) 9
d) 10
10) A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below.
|0|   | 
|1|   |
|2| 42|
|3| 23|
|4| 34|
|5| 52|
|6| 46|
|7| 33|
|8|   |
|9|   |
Which one of the following choices gives a possible order in which the key values could have been inserted in the table?
a) 46, 42, 34, 52, 23, 33
b) 34, 42, 23, 52, 33, 46
c) 46, 34, 42, 23, 52, 33
d) 42, 46, 33, 23, 34, 52
11) How many different insertion sequences of the key values using the same hash function of question 10 and linear probing will result in the hash table shown above?
a) 10
b) 20
c) 30
d) 40
12) The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs is
a) T(n) = 2T(n – 2) + 2
b) T(n) = 2T(n – 1) + n
c) T(n) = 2T(n/2) + 1
d) T(n) = 2T(n – 1) + 1
13) Given three semaphores, S0, S1 and S2 initialized as S0=1, S1=0, S2=0 and processes P0, P1 and P2.
P0 : while(true)
P0, P1 and P2.
P0 : while(true)
{
  wait(S0);
  printf(“ 0 “);
  Release(S1);
  Release(S2);
}
P1: while(true)
{
  Wait(S1);
  Release(S2);
}
P2: while(true)
{
  Wait(S2);
  Release(S0);
} 
Find out how many times the process P0 executes printf statement.
a) At least twice
b) Exactly once
c) Exactly twice
d) Exactly thrice
14) Given the following program construct
{
 if ( a == b ) { S1; exit(); }
 else if ( c==d ) { S2; }
 else { S3; exit(); }
 S4;
} 
Given 4 test cases, find out which one among the following covers all the 4 statements
T1: a, b, c and d are same.
T2: a, b, c and d are all distinct.
T3: a == b and c != d.
T4: a != b and c==d.
a) T1, T2 & T3;
b) T1, T4.
c) T2, T4.
d) T1, T2 & T4.
15) Which of the following statements are true?
I. Shortest remaining time first scheduling may cause starvation
II. Preemptive scheduling may cause starvation
III. Round robin is better than FCFS in terms of response time
a) I only
b) I and III only
c) II and III only
d) I, II and III
16) Sequences of logical pages access :
1 2 3 2 4 1 3 2 4 1
Implemented Optimal,LRU,FIFO Page replacement techniques.
Then no. of page faults in :
a) Optimal < LRU < FIFO b) Optimal < FIFO < LRU c) Optimal = FIFO d) None 17) Find the no. of page faults for Optimal Page replacement technique in the given sequence of question no. 16.
a) 5
b) 6
c) 7
d) 8
18) Given a simple graph of 6 nodes (note- it’s a simple graph) then tell which of the following is a set of valid graph degrees.
a) 4,4,1,1,1,1
b) 4,4,2,1,1,1
c) 4,4,2,2,1,1
d) None
19)
gcd(n,m)
{
  if (n%m == 0)
    return n;
  n = n%m;
  return gcd ( m, n);
} 
What is the complexity of calculating gcd(n, m) in worst case?
a) O(lgn)
b) O(lgm)
c) O(lg(lgn))
d) O(lg(lgm))
20)
void f(char * x)
{
  x++;
  *x = 'a';
}
int main()
{
  char * str = "hello";
  f(str);
  cout << str;
  system("pause");
  return 0;
} 
a) hello
b) hallo
c) allo
d) empty string
SECTION B – Subjective Question
A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square exactly once. Find all the distinct tours of a knight placed on (x,y) of a NxN chessboard.
X,Y Knight can go to 8 positions.(default rule). Write a running code.

Saturday, February 20, 2016

Google Latest placement papers Questions answers

                                       


About Company: 

                     Google Inc. is an American multinational technology company specializing in Internet-related services and products. These include online advertising technologies, search, cloud computing, and software.



Google placement paper questions with answers. Google programming questions sample placement papers of aptitude questions coding questions.
1) Given four matrices
P = 20×10
Q = 10×5
R = 5×10
S = 10×10

Find minimum no. of multiplication required for PxQxRxS?

Friday, February 19, 2016

Amazon Placement Paper Freshers - Interview Questions

Amazon Placement Paper Freshers - Interview Questions

 
  

  Company Name:  Amazon
  Interview Location:  Hyderabad 
   Written Test has 2 Sections A, B



                       

In Section A there were 20 Questions: 
Technical Questions: 15
Aptitude: 5
Time: 30 min

The first round was online, It had 20 Multiple choice questions and 2 coding, MCQ’s where quite simple, Technical where easy it had questions on finding the Output, Complexity, and more importance was in Data Structure, and especially TREE. 

Some Sample Questions
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.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.what is x here (x&&!(x&(x-1))==1)
a)x is always a prime
b)x is a power of 2
c)x is 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 child ?

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 twice 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 probability to pick a pair of black or white socks when 2 socks are selected randomly 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)