Answer:
Divide the stones into sets like (3,3,2). Use pan to weigh (3,3).
If the pan is remains balanced, the heavier is in the remaining (2). use pan again to find which is heavy from (2). (Total pan use 2)
If the pan does not remain balanced when weighing (3,3), pick the set of stones that outweigh other. Divide it into (1,1,1). use pan to weigh first two. It it remains balanced, the remaining stone is the heavier, otherwise the one outweighing other is heavier(total pan use 2)
[These questions from 'Taher']
* 2^n * n^Googol ( 10^100) * n! * n^n
Answer: n^(whatever constant), 2^n, n! (==> n^n / e^n ), n^n
Answer:
Best is O(c), worst is O(log n)
* What do you need when you instantiate a string ( i said a byte array and possibly the length) ?
* What is the best and worst time for the operation 'equals'
* How do you spedup the 'equals' operation (i said used hash MD5 for example)
This still has some problem ( a hash can be the same for unequal strings)
-> Use Boyer–Moore string search algorithm => O(n)
For example, let consider (6, 3, 1, 2). We need to find these products :
last one is simple
int mul = 1;
for i = 1 to N
mul *=a[i];
for i= 1 to N
a[i] = mul/a[i];
(I got this question, your answer is not correct)
First of all if a[i]=0 you get an exception, the guy wanted me to use dynamic programming to solve this.
Here's the dynamic programming solution:
You want to build a table where x[i,j] holds the product of (ni .. nj). If you had such a table, you could just output
for (int i = 1; i <= n; i++)
{
if (i == 1)
print x[2,n];
else if (i == n)
print x[1,n-1];
else
print x[1,i-1] * x[i+1,n];
}
To build the table, start along the diagonal (x[i,i] = ni). Then do successive diagonals from previous ones (x[j,k] = x[j-1,k] * x[j,k+1]).
Binary tree - requires 1,000,000 integers x 4 bytes = 4 MB + left pointer and right pointer = 12 MB
Insertion sort - can be done in under 4 MB
a) simple answer - start at 2 and divide the integer by each successive value. If it divides evenly before you reach half way then it is.
b) complex answer after much leading - Do the bitwise AND of n and (n-1). If it is zero then it is a square (I think this is wrong. This actually tests whether n is a power of 2).
No, it almost tests whether n is power of 2. It falsely proclaims 0 to be a power of 2. More info: http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
C)
i=2;
while(!NO)
{
if((i*i)==Number)
{
NO;
return True;}
if((i*i)>Number)
{
NO;
return false;}
i++;
}
5428907816463810488188
Here are some questions I got on my first interview with Google (slightly altered for NDA reasons).
do to organize your shirts for easy retrieval?
www.technical-interview. com Google Interview Questions
Phone interview
1. Describe the data structure that is used to manage memory. (stack)
2. whats the difference between local and global variables?
3. If you have 1 million integers, how would you sort them efficiently? (modify a specific sorting algorithm to solve this)
4. In Java, what is the difference between static, final, and const. (if you dont know java they will ask something similar for C or C++).
5. Talk about your class projects or work projects (pick something easy)… then describe how you could make them more efficient (in terms of algorithms).
In person interview
1. In Java, what is the difference between final, finally, and finalize?
2. What is multithreaded programming? What is a deadlock?
3. Write a function (with helper functions if needed) called toExcel that takes an excel column value (A,B,C,D…AA,AB,AC,… AAA..) and returns a corresponding integer value (A=1,B=2,… AA=26..).
4. You have a stream of infinite queries (ie: real time Google search queries that people are entering). Describe how you would go about finding a good estimate of 1000 samples from this never ending set of data and then write code for it.
5. Tree search algorithms. Write BFS and DFS code, explain run time and space requirements. Modify the code to handle trees with weighted edges and loops with BFS and DFS, make the code print out path to goal state.
6. You are given a list of numbers. When you reach the end of the list you will come back to the beginning of the list (a circular list). Write the most efficient algorithm to find the minimum # in this list. Find any given # in the list. The numbers in the list are always increasing but you don’t know where the circular list begins, ie: 38, 40, 55, 89, 6, 13, 20, 23, 36.
Here is a bunch more:
Recent comments
1 year 3 weeks ago
1 year 9 weeks ago
1 year 10 weeks ago
1 year 11 weeks ago