Thursday, February 25, 2010

Hungry Elephant


This one is easy and most famous puzzle.
But I have a doubt here which I would post later after getting answers .

There are 2 cities A and B, distance between them is 1000 Km.
we have 3000 bananas in city A and a elephant
can carry max 1000 bananas at any given time and it needs to eat a banana every 1 Km.

How Many Max. No. of bananas you can transfer to city B ?.

Wednesday, February 24, 2010

Boat and Dock


You are Sitting in a small boat holding the end of a rope.The other end of the rope is tied to the top of
a nearby pier (See figure) , such that the it is higher above the water than your end of the rope,Causing your boat to move towards the pier,stopping directly underneath the pier.As you pull on the rope, which is moving faster :boat or the rope?
i.e the speed of the boat moves across the water or the speed the rope moves through your hands.

Looks like difficult one but not exactly.

Tuesday, February 23, 2010

PJ Puzzle


In which direction is the bus moving?
Right or Left?

Monday, February 22, 2010

Blind Man and Cards


A blind man is handed a deck of 52 cards and told that exactly 10 of these cards are facing up. How can he divide the cards into two piles, not necessarily of equal size, with each pile having the same number of cards facing up?

Sunday, February 21, 2010

Adobe Interview Round2

Only 2 questions where asked.
we had to write complete algorithm for them.

1) int a[]= {1,1,1,2,2,3,3,3,3,4,5};
o/p shud be 1,3,2,2,3,4,4,1,5,1

i.e 1 followed by how many times 1 is repeated.

2) a ={1,1,1,2,2,3,3,3,4,4,5};
b={1,2,2,3,6};

o/p c = {6,5,4,3,2,1};

Adobe Interview Round1

1) Basic C++ question .A class definition was given and then objects of that class were created in main function.
like
class string
{
int a;
int b;
int c;
void print()
{
printf("%d%d%d",&a,&b,&c);
}

};

main()
{
string s1,s2;
s1.a=s1.b=s1.c=10;

s1 =s2;
s1.print();
string s3=s2;
s3.print();
s2.print();
}

basically he was trying to get whether i understood what happens when s1=s2 and at string s3=s2;

2) What is the difference between a big endian and little endian machine?
Can you write a code to identify them.

sol int x=1;

if(x<<1)
printf("big endian");
else "little endian";


3)Do you know what is inorder traversal and BFS.
given a sample tree do that.
write code for inorder.
I wrote recursive then he asked me for iterative.

4)An array of numbers is given which are sorted you are also given a number 'X'.
you need to print to 2 elements of array such that there sum is X.


since the elements are sorted , to search for any element we can for binary search. now subtract x from a[0] and search for the result in array.
this wud cost me o(nlogn)


5) Given i/p "My name is khan" o/p shud be "khan is my name"

one approach wud be to use linked list , wherein we use each node to store a word.

my->name->is->khan.

Now do linked list reverse operation.

by using this even multiple space between words can be taken care of.
my->space,space->name->...
i.e in the node which stores space i will store that many space characters which are present.

Interviewer asked me to get a solution without extra memory usage.
DO string reversal nahk si eman ym
now do word by word reverse khan is name my

6)char a[]="string"; char *p="string";
there are several difference b/w a and p
most imp one is that u can do free(p) but not free(a);

Tuesday, February 16, 2010

How will you measure?

You are given 2 containers one is of 5 liters capacity and other is 3 liters.
Measure 4 liters using the above two containers only.(You are given unlimited supply of water , containers are unmarked).


Start from the 5 liters can fill it and empty it in to 3 liters.
So now you have 2 liters in 5 liter can and 3 liters can is full.
Empty 3 liters can . And move 2 liters from 5 liter can to 3 liter can.
Now 3 liter can has 2 liters and 5 liter can is empty.
Now Again fill 5 liter can . Transfer as much as you can in 3 liters can.
Since you are left with only 1 liter volume in 3 liter can you can transfer only 1 liter into it.So you are left with 4 liters in 5 liters can now.

50-> 23 -> 20 -> 02 -> 52 -> 43.


Mathematically

5x+3y = 4
x = 2 y =-2 Therefore |x| + |y| = 4

i.e we need to find x and y values such that |x|+|y| is minimum.

So x here means take water 2 times from 5 liter can and drain out water from 3 liter can 2 times.

One more

There is an ample supply of milk in a milk tank. You have a 5-liter and a 9-liter cans, both of them unmarked. How can you measure out 2 liters?.

5X + 9Y = 2

X = 4 and Y = -2

50 -> 05 -> 55 -> 19 -> 10 -> 01 -> 51 -> 06 -> 56 -> 29.

done!!

Monday, February 15, 2010

Adobe Written Test Section II

Here it goes!!

11) 2’s Complement representation of (-5)

12)Input is reverse polish notation of an expression. WAP to evaluate the exression

i/p 235+*
o/p 16

[Reverse polish is nothing but postfix ]

13) WAP to find the depth of a tree

14) WAP to copy ‘n’ bits from pth posn (from LSB) of a number to another at p th posn from USB.

15)Binary search program was given which has 3 If statements in it
Like a[mid]< x , a[mid] > x and a[mid] == x
We were asked to reduce the no of if statements.
(I guess soln is to use ?: operator)

16)Few simple c questions like
Char a[]=”string”;
Char *a= “string”; what is the diff btw these 2 a’s?

17)What are bitfields.Where are they used?

18)what are data breakpoints.Give 2 applications where it is used.

19)double degC ,degF;

DegC = 5/9 *(degF-9);
I don’t remember the exact conversion formula.
Point here is that 5/9 should be typecasted to get correct result.

20) only 1 question is left which I don’t remember ;-)

Adobe Written Test Section I

Well my feedback for this test would be it was easy not so tough (if you had atleast prepared with basic stuff).All direct questions were there.
Set included few standard questions like to find the depth of a tree.
conversion of a hexadecimal number to integer etc,..


I know most of the people from north India staying here at bangalore wud like to get into adobe for there own reasons(near to home,gud sal etc..).

It seems like the adobe fellas are bit lazy in changing the question paper.
This paper was repeating from past 1 month, ditto paper not even a comma change.
I came to know about this after the test :( .

So this for all those desparate junta who wants to get in to adobe.


There were 2 sections one on C and other on Algorithms .

Section I:


1) WAP to check the equality of two trees

2) Draw the tree structure given an infix equation and write the postfix equation for the same

a*(b+c/d)*e-f;

3) assembly code given : we have to find whats it does. Only one register is there

Load X
MULT Y
STORE T1
LOAD T1
MULT T1
LOAD Y
ADD Z
MULT T1
STORE R

(I am not so sure about the above statements and they gave 4 choices. We have to choose among them)


4)A shared queue is there between 2 threads T1,T2 .
T1 writes in to queue and T2 reads from the queue.
T1 cannot write when the queue is full and T2 cannot read when the queue is empty.
Write an solution for this situation.
you are given following operators
createEvent
Event.setName
Event.Reset
enterCriticalSection
Leave Critical Section
Wait
etc,.

[Producer Consumer problem]


5) They gave some assembly instructions and asked to write the following c code in assembly

a=300;
for(i=10;i>0;i--)
a=a+200;

available assembly codes are push #number , add NO(adds the NO to top stack element and pushes it to stack again) ,sub,exchange ( changes the postion of 2 top numbers in stack),JNZ (tricky : loops back if the top element is non zero and Pops out the top element), duplicate – pushes a duplicate entry of top element back to stack.



6) There are some (c1….cn) computers connected by k connections. Write a algorithm to find out if all the computers are connected ?
Connections are transitive and symmetric .
( Any solutions for this question are welcome )


7) The gave a BST tree structure and u have to find the 4th smallest element in the tree…..

8)
A stack implementation was given whose size was 1….N.

Push begin v[i] : = x; i=i+1 end;

Pop begin i=i-1 x=v[i] end;

3 options were given. We need to identify which operation has to be done so that push and pop work properly.
They were something like
1)Replace statements of pop with that of push
2)Exchange statements In push and in pop.(i.e make v[i]=x as 2nd stmnt and i=i+1 as 1st stmnt.
etc…

9)WAP for Conversion of hexadecimal to integer.
You need to consider even 'a' and 'A'.
Input can be oxabc or OXAbF


10)There was a question on drawing a line from one given point to other.
You are given a function like drawpoint(double x, double y);
WAP to draw a line from point p1 to point p2.