Showing posts with label Google. Show all posts
Showing posts with label Google. Show all posts

Wednesday, September 14, 2011

GOOGLE PAPER On 3rd Sept 2006,CHENNAI


The criteria was first 30% topper in the class. So around 40 students has attended the test & only 4 could clear the test.

Test consist of 15 question based on C, C++, and Data Structure and two C programs. So i am listing some of the question as i remembered.

Q1) What is the value of i after execution of the following program.
void main()
{
long l=1024;
int i=1;
while(l>=1)
{ l=l/2;
i=i+1;
}
}
a)8 b)11 c)10 d)100 ans:b

Q2) This question is based on the complexity ...

Q3)
s->AB
A->a
B->bbA
Which one is false for above grammer..

Q3) Some Tree were given & the question is to fine preorder traversal.

Q4) One c++ program,to find output of the program..

Q5) If the mean faliure hour is 10,000 and 20 is the mean repair hour.If the printer is used by 100 customer, then find the availability. http://www.ChetanaS.org
1)80% 2)90% 3)98% 4)99.8% 5)100%

Q6) One question on probability...

Q7) In a singly linked list if there is a pointer S on the first element and pointer L is on the last element. Then which operation will take more time based on the lenght of the list.
1) Adding element at the first.
2) adding element at the end of the list.
3) To exchange the fisrt 2 element.
4) Deleting the element from the end of the list.
ans:2 check it!

3 more question to fine the output of the program and rest of the question was based on Data Structure,

some condition were given and we have to conlude either y or n

The Second Section was coding...

1) Write a fucntion to multiply 2 N*N matrix
Write test cases for ur code.

2) S contains the set of positive integer. Find the largest number c such that c=a+b where a,b,c are distict number of the set.

GOOGLE PAPER - JAN 2005


Google Placement Paper and Sample Paper

1. Solve this cryptic equation, realizing of course that values for M and E could be interchanged. No leading zeros are allowed.

WWWDOT - GOOGLE = DOTCOM

This can be solved through systematic application of logic. For example, cannot be equal to 0, since . That would make , but , which is not possible.

Here is a slow brute-force method of solution that takes a few minutes on a relatively fast machine:
This gives the two solutions
777589 - 188106 == 589483
777589 - 188103 == 589486

Here is another solution using Mathematica's Reduce command:
A faster (but slightly more obscure) piece of code is the following:

Faster still using the same approach (and requiring ~300 MB of memory):

Even faster using the same approach (that does not exclude leading zeros in the solution, but that can easily be weeded out at the end):

Here is an independent solution method that uses branch-and-prune techniques:

And the winner for overall fastest:

2. Write a haiku describing possible methods for predicting search traffic seasonality.

MathWorld's search engine
seemed slowed this May. Undergrads
prepping for finals.

3. 1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
What's the next line?

312211. This is the "look and say" sequence in which each term after the first describes the previous term: one 1 (11); two 1s (21); one 2 and one 1 (1211); one 1, one 2, and two 1's (111221); and so on. See the look and say sequence entry on MathWorld for a complete write-up and the algebraic form of a fascinating related quantity known as Conway's constant.

4. You are in a maze of twisty little passages, all alike. There is a dusty laptop here with a weak wireless connection. There are dull, lifeless gnomes strolling around. What dost thou do?

A) Wander aimlessly, bumping into obstacles until you are eaten by a grue.
B) Use the laptop as a digging device to tunnel to the next level.
C) Play MPoRPG until the battery dies along with your hopes.
D) Use the computer to map the nodes of the maze and discover an exit path.
E) Email your resume to Google, tell the lead gnome you quit and find yourself in whole different world [sic].

In general, make a state diagram . However, this method would not work in certain pathological cases such as, say, a fractal maze. For an example of this and commentary, see Ed Pegg's column about state diagrams and mazes .

5. What's broken with Unix?

Their reproductive capabilities.

How would you fix it?

6. On your first day at Google, you discover that your cubicle mate wrote the textbook you used as a primary resource in your first year of graduate school. Do you:

A) Fawn obsequiously and ask if you can have an autograph.
B) Sit perfectly still and use only soft keystrokes to avoid disturbing her concentration chetanasinterview.com
C) Leave her daily offerings of granola and English toffee from the food bins.
D) Quote your favorite formula from the textbook and explain how it's now your mantra.
E) Show her how example 17b could have been solved with 34 fewer lines of code.

7. Which of the following expresses Google's over-arching philosophy?

A) "I'm feeling lucky"
B) "Don't be evil"
C) "Oh, I already fixed that"
D) "You should never be more than 50 feet from food"
E) All of the above

8. How many different ways can you color an icosahedron with one of three colors on each face?

For an asymmetric 20-sided solid, there are possible 3-colorings . For a symmetric 20-sided object, the Polya enumeration theorem can be used to obtain the number of distinct colorings. Here is a concise Mathematica implementation:

What colors would you choose?

9. This space left intentionally blank. Please fill it with something that improves upon emptiness.

For nearly 10,000 images of mathematical functions, see The Wolfram Functions Site visualization gallery .

10. On an infinite, two-dimensional, rectangular lattice of 1-ohm resistors, what is the resistance between two nodes that are a knight's move away?

This problem is discussed in J. Cserti's 1999 arXiv preprint . It is also discussed in The Mathematica GuideBook for Symbolics, the forthcoming fourth volume in Michael Trott's GuideBook series, the first two of which were published just last week by Springer-Verlag. The contents for all four GuideBooks, including the two not yet published, are available on the DVD distributed with the first two GuideBooks.

11. It's 2PM on a sunny Sunday afternoon in the Bay Area. You're minutes from the Pacific Ocean, redwood forest hiking trails and world class cultural attractions. What do you do?

12. In your opinion, what is the most beautiful math equation ever derived?

There are obviously many candidates. The following list gives ten of the authors' favorites:

1. Archimedes' recurrence formula : , , ,
2. Euler formula :
3. Euler-Mascheroni constant :
4. Riemann hypothesis: and implies
5. Gaussian integral :
6. Ramanujan's prime product formula:
7. Zeta-regularized product :
8. Mandelbrot set recursion:
9. BBP formula :
10. Cauchy integral formula:
http://www.ChetanaS.com
An excellent paper discussing the most beautiful equations in physics is Daniel Z. Freedman's " Some beautiful equations of mathematical physics ." Note that the physics view on beauty in equations is less uniform than the mathematical one. To quote the not-necessarily-standard view of theoretical physicist P.A.M. Dirac, "It is more important to have beauty in one's equations than to have them fit experiment."

13. Which of the following is NOT an actual interest group formed by Google employees?
A. Women's basketball B. Buffy fans C. Cricketeers D. Nobel winners E. Wine club

14. What will be the next great improvement in search technology?

Semantic searching of mathematical formulas. See http://functions.wolfram.com/About/ourvision.html for work currently underway at Wolfram Research that will be made available in the near future.

15. What is the optimal size of a project team, above which additional members do not contribute productivity equivalent to the percentage increase in the staff size?
A) 1 B) 3 C) 5 D) 11 E) 24

16. Given a triangle ABC, how would you use only a compass and straight edge to find a point P such that triangles ABP, ACP and BCP have equal perimeters? (Assume that ABC is constructed so that a solution does exist.)
This is the isoperimetric point , which is at the center of the larger Soddy circle. It is related to Apollonius' problem . The three tangent circles are easy to construct: The circle around has diameter , which gives the other two circles. A summary of compass and straightedge constructions for the outer Soddy circle can be found in " Apollonius' Problem: A Study of Solutions and Their Connections" by David Gisch and Jason M. Ribando.

17. Consider a function which, for a given whole number n, returns the number of ones required when writing out all numbers between 0 and n. For example, f(13)=6. Notice that f(1)=1. What is the next largest n such that f(n)=n?

The following Mathematica code computes the difference between [the cumulative number of 1s in the positive integers up to n] and [the value of n itself] as n ranges from 1 to 500,000:
http://www.ChetanaSinterview.com
The solution to the problem is then the first position greater than the first at which data equals 0:

which are the first few terms of sequence A014778 in the On-Line Encyclopedia of Integer Sequences.

Checking by hand confirms that the numbers from 1 to 199981 contain a total of 199981 1s:

18. What is the coolest hack you've ever written?

While there is no "correct" answer, a nice hack for solving the first problem in the SIAM hundred-dollar, hundred-digit challenge can be achieved by converting the limit into the strongly divergent series:

and then using Mathematica's numerical function SequenceLimit to trivially get the correct answer (to six digits),

You must tweak parameters a bit or write your own sequence limit to get all 10 digits.

19. 'Tis known in refined company, that choosing K things out of N can be done in ways as many as choosing N minus K from N: I pick K, you the remaining.

This simply states the binomial coefficient identity .

Find though a cooler bijection, where you show a knack uncanny, of making your choices contain all K of mine. Oh, for pedantry: let K be no more than half N.

'Tis more problematic to disentangle semantic meaning precise from the this paragraph of verbiage peculiar.

20. What number comes next in the sequence: 10, 9, 60, 90, 70, 66, ?

A) 96
B) 1000000000000000000000000000000000\
0000000000000000000000000000000000\
000000000000000000000000000000000
C) Either of the above
D) None of the above

This can be looked up and found to be sequence A052196 in the On-Line Encyclopedia of Integer Sequences, which gives the largest positive integer whose English name has n letters. For example, the first few terms are ten, nine, sixty, ninety, seventy, sixty-six, ninety-six, . A more correct sequence might be ten, nine, sixty, googol, seventy, sixty-six, ninety-six, googolplex. And also note, incidentally, that the correct spelling of the mathematical term " googol" differs from the name of the company that made up this aptitude test.

The first few can be computed using the NumberName function in Eric Weisstein's MathWorld packages:

A mathematical solution could also be found by fitting a Lagrange interpolating polynomial to the six known terms and extrapolating:

21. In 29 words or fewer, describe what you would strive to accomplish if you worked at Google Labs.

Sunday, August 28, 2011

Google Top Interview Puzzles




  • 1. There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1] will be multiplication of A[0] and from A[2] to A[N-1].

    Solve it without division operator and in O(n).





  • 2. There is a linked list of numbers of length N. N is very large and you don’t know N. You have to write a function that will return k random numbers from the list. Numbers should be completely random.

    Hint:

    1. Use random function rand() (returns a number between 0 and 1) and irand()
    (return either 0 or 1)
    2. It should be done in O(n).





  • 3. Find or determine non existence of a number in a sorted list of N numbers where the numbers range over M, M >> N and N large enough to span multiple disks. Algorithm to beat O(log n) bonus points for constant time algorithm.





  • 4. You are given a game of Tic Tac Toe. You have to write a function in which you pass the whole game and name of a player. The function will return whether the player has won the game or not. First you to decide which data structure you will use for the game.You need to tell the algorithm first and then need to write the code.

    Note: Some position may be blank in the game। So your data structure should
    consider this condition also.





  • 5. You are given an array [a1 To an] and we have to construct another array [b1 To bn] where bi = a1*a2*...*an/ai. you are allowed to use only constant space and the time complexity is O(n). No divisions are allowed.





  • 6. How do you put a Binary Search Tree in an array in a efficient manner.


    Hint :: If the node is stored at the ith position and its children are at
    2i and 2i+1(I mean level order wise)Its not the most efficient way.





  • 7. How do you find out the fifth maximum element in an Binary Search Tree in efficient manner.

    Note :: You should not use use any extra space. i.e sorting Binary Search Tree
    and storing the results in an array and listing out the fifth element.





  • 8. Given a Data Structure having first n integers and next n chars. A = i1 i2 i3 ... iN c1 c2 c3 ... cN.Write an in-place algorithm to rearrange the elements of the array ass A = i1 c1 i2 c2 ... in cn





  • 9. Given two sequences of items, find the items whose absolute number increases or decreases the most when comparing one sequence with the other by reading the sequence only once.





  • 10. Given That One of the strings is very very long , and the other one could be of various sizes. Windowing will result in O(N+M) solution but could it be better? May be NlogM or even better?





  • 11. How many lines can be drawn in a 2D plane such that they are equidistant from 3 non-collinear points ?





  • 12. Lets say you have to construct Google maps from scratch and guide a person standing on Gateway of India (Mumbai) to India Gate(Delhi).How do you do the same ?





  • 13. Given that you have one string of length N and M small strings of length L . How do you efficiently find the occurrence of each small string in the larger one ?





  • 14. Given a Binary Tree, Programmatically you need to Prove it is a Binary Search Tree
    Hint: Some kind of pointer handling with In Order Traversal - anybody in for
    writing some code





  • 15. You are given a small sorted list of numbers, and a very very long sorted list of numbers - so long that it had to be put on a disk in different blocks. How would you find those short list numbers in the bigger one?





  • 16. Suppose you have given N companies, and we want to eventually merge them into one big company. How many ways are theres to merge?





  • 17. Given a file of 4 billion 32-bit integers, how to find one that appears at least twice?





  • 18. Write a program for displaying the ten most frequent words in a file such that your program should be efficient in all complexity measures.





  • 19. Design a stack. We want to push, pop, and also, retrieve the minimum element in constant time.





  • 20. Given a set of coin denominators, find the minimum number of coins to give a certain amount of change.





  • 21. Given an array,

    i) find the longest continuous increasing subsequence.

    ii) find the longest increasing subsequence.





  • 22. Suppose we have N companies, and we want to eventually merge them into one big company. How many ways are there to merge?





  • 23. Write a function to find the middle node of a single link list.





  • 24. Given two binary trees, write a compare function to check if they are equal or not. Being equal means that they have the same value and same structure.





  • 25. Implement put/get methods of a fixed size cache with LRU replacement algorithm.





  • 26. You are given with three sorted arrays ( in ascending order), you are required to find a triplet ( one element from each array) such that distance is minimum.

    Distance is defined like this :

    If a[i], b[j] and c[k] are three elements then

    distance=max(abs(a[i]-b[j]),abs(a[i]-c[k]),abs(b[j]-c[k]))"

    Please give a solution in O(n) time complexity





  • 27. Classic - Egg Problem

    You are given 2 eggs.You have access to a 100-storey 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-storey 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.



  • Google Interview Questions



    Google Interview Questions ::

    Total there are five Technical Interviews followed by Management round.

    So here are the questions.

    Google Interview Round 1 ::

    1. What is the Space complexity of quick sort algorithm? how do find it?

      Solution: Quicksort has a space complexity of O(logn), even in the worst case, when it is carefully implemented such that
      * in-place partitioning is used. This requires O(1).
      * 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.
      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.

      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.
    2. What are dangling pointers?

      Solution: 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.
    3. 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.

      Solution:The simple recurrence relation governing this problem is f(N)=f(N-1) +f(N-2)(why?),which is a fibonacci sequence.
      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.
    4. You are given biased coin. Find unbiased decision out of it?

      Solution: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.
    5. 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.


    Google Interview Round 2 ::

    1. 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.

      Solution:
      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.

      Sum of first N natural numbers=N*(N+1)/2

      and S=N*(N+1)/2 - K.Now putting this other way around we get K=N*(N+1)/2 -S !!



      Now the second part of the question says that there are 2 of the first N numbers missing.Let they be X and Y.

      We solve this problem by solving 2 essential equations.



      They are X+Y=N*(N+1)/2 -S---------->(1)

      X*Y=N!/P-------------------(2) where S and P are the cumulative sum and product of the array entries.
    2. You have cycle in linked list. Find it. Prove that time complexity is linear. Also find the node at which looping takes place.

      Solution:
      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.

      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

      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.
    3. Questions on my project please be prepare well about your project
    4. How do you search for a word in a large database.
    5. 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'.

    Google Interview Round 3 ::

    1. You have given an array. Find the maximum and minimum numbers in less number of comparisons.

      Solution:
      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.
    2. 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).

      Solution: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.

    Google Interview Round 4 ::

    1. Three strings say A,B,C are given to you. Check weather 3rd string is interleaved from string A and B.
      Ex: A="abcd" B="xyz" C="axybczd". answer is yes.


      Solution:
      bool test(A,B,C)
      {
        i=j=k=0;
        while(k < C.size())
        {
          if(i < A.size() && C[k]==A[i])
           {i++,k++;
           }
          else if(j < B.size() && C[k]==B[j])
          {
            j++,k++;
          }
          else
          return false  
        }
        return (i == A.size() && j == B.size());
      } 

      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.
    2. Given two sorted arrays A and B.
      1. Find the intersection of these arrays A and B.

        Solution:The intersection can be found by using a variation of merge routine of the merge sort.
      2. If array A is small and array B is too large. how will you proceed for getting intersection of those two arrays?

        Solution:In this case for each entry of smaller array,we can run a binary search routine on the larger one to know its presence.

    Google Interview Round 5 ::

    1. If you get into Google, which products are you going to work on?
    2. What is TCP, UDP. what is reliability, unreliability, give examples of these?

      Solution:
      Click Here To Read About TCP
      Click Here To Read About UDP
      Click Here To Read About Reliability
    3. What is http protocol?

      Solution:
      Click Here To Read About HTTP
    4. How does Google search engine works?
    5. What is indexing, what is the input and output to it. how Google does that?

    ShareThis

     
    View My Stats