Thursday, November 27, 2008

Trilogy Interview of Sandeep Jain

Written:

There were 4 questions, 3 of coding & 1 was for debugging. We were asked to write algorithm, code with comments & proper naming conventions

I attempted-
1st question completely
2nd was correct, but my approach was not the best
3rd was able to write only the initial approach about the problem
I couldn’t attempt the 4th one

So as such you guys need not worry about attempting all the questions. There were two telephonic interviews, and in both the interviews the interviewer first gave his formal introduction & then asked me for my intro.

So here goes the description...


First round tech Interview:

TRI: Tell me something about any recent project that you did, the one you like the most.
I described the GSD project, and my role in it. (GSD was the best project in terms of what I had learned)

TRI: Given a general stack implementation, can you write a function MAX(s) that returns the current maximum value in the stack?
ME: I gave him two O(n) solutions, basically to scan the array or link list used to implement the stack
TRI: Which is a better approach, array or Link list in terms of efficiency?
ME: Array, due to locality of reference
TRI: Good, but I want the MAX to be returned in O(1)
ME: (After 2 mins of thinking) Can I modify the Data Structure

Well he agreed to modify the DS but by using my approach the original push/pop operations became O(n). He had some discussions even thou he was satisfied with my approach he wanted me to improve my approach. His only requirement was to have push, pop & max functions to be O(1). I got stuck at this point. Then he gave me sample data to work upon. Using the given data I was able to correct my approach and finally gave him the correct solution.

TRI: The next problem goes like this, suppose I give you an integer array, Can you generate all triplets such that a^2 + b^2 = c^2 where a, b, c are all elements of the array?
ME: I said, I have done a similar question, where we find all pairs a[i] & a[j] such that a[i] +a[j] =X, I can you use this approach.
TRI: Ok go ahead.

I gave him an O(n^2) solution. Then I told him that I can optimize by calculating the square and replacing the contents of each element by the corresponding square. This will reduce computations regarding squaring of elements again & again. He was impressed with this approach. The problem then reduces to finding triplets such that X+Y = Z.

TRI: Can you write the code for it? Take your time & then dictate me complete error free code. (He asked me about the signature of the function, name & type of variable too.)

TRI: You must know about tree, traversals. Can you write code to perform a level wise traversal of a binary tree?
ME: Sir I know this problem, Shall I continue.
TRI: Is that so, well then just give me an overview.
I dictated him the entire code. :D

TRI: Suppose we have two nodes of a binary tree; find its least common ancestor. I hope you don’t know this one.
ME: Not, exactly, but I did this problem, a few months ago.
TRI: Ok then do it for a BST
I gave him the approach; he was satisfied with it & asked me to tell the order of the algorithm. Its O(lg N) guys.

TRI: Well, Mr. Sandeep your interview went pretty well & that’s all I wanted to discuss. Would you like to ask me anything?
ME: I do not have any particular question. I just hope there is no problem with my call getting disconnected.



Second round tech Interview:

This was a tough one; I can’t give the entire description. But trust me I was shivering & sweating during the interview. There was only one question; I had to implement a game.

It goes something like this-
There are two 3-letter words for e.g. CAT & TRY
If you are allowed to alter any single letter then in how many steps can you convert CAT into TRY, the only constraint is that the intermediate words should be valid 3-letter words.
I asked him if we have a repository of words. He said I can assume a dictionary with all possible 3-letter words.
We discussed the algorithm for around 25-30 mins. After which I was asked to write a code for it, such that we can calculate the minimum number of steps required (as there are many chains possible or we may have none).
So return -1 if we cannot convert Source to Destination.
After 15-20 mins of coding. He further made me optimize the code. I had given him a recursive approach, which scanned the DB in a DFS manner. He made me convert my code to BFS, & then asked me to compare the two in terms of efficiency & space.

This one question covered: String matching, Hashing, General Tree, BFS, DFS, Recursion, Tail-Recursion, Tree pruning, & god knows what...
One thing was for sure I was exhausted after the interview... BUT it was an awesome experience.

All The best... :)

Monday, September 15, 2008

Adobe Interview of Rinky Gupta

Q: Given length and precision(ex: 1/8) draw scale. each unit shd have different height. Draw same as the scale we generally use.

Q: a)Implement stack.(write constructor, destructor,push,pop).
b)Implement Quesue using stack. Optimise the enqueue and dequeue operations.

Q: Difference b/w program and process. How a process executes(Interviewer was expecting program counter etc etc)


Q: There are 3 string S1, S2 and S3. Replace all occurances of S2 in S1 with S3. S3 and S2 can be of any length. Length of S2 can be greater equal or less than that of S3. Result is new string.

Q: There are n guests in a party. A guest can make any numbr of handshakes(0 to n-1) . Prove that there are atleast 2 guest having same number of handshakes.(Can be proved using induction as well as Contradiction)

Q: Difference b/w reference and pointer and where do we use each. What is advantage of 1 over other. When is the memory allocated for each.

Q: Two trains are moving towards each other with different speeds on same track. A bird is moving to and fro. Find the distance travlled by bird till the trains meet.

Q: 100 floors. 2 eggs. find the lowest floor from which the egg breaks in min number of throws.

Q: 50 Red balls and 50 blue balls. 2 empty baskets. A person has to choose 1 basket at random and then pick 1 ball out of it at random. Distribute the balls to maximise the probability of picking up red ball.

Q: Find the subsequence of max sum from array of +ve and -ve numbers.

Q: There is an array of N elements having values in range 0 to N-1. a value can be repeated any number of times. Do some preprocessing so that the count of a particular value can be determined in O(1) after preprocessing. Do not use any extra array to store the counts. Same array can be modified to strore counts for each value.

Q: A float f is given and digits d. return the string having the value with d sigits after decimal.

Q: a)Find the maximum and the min value an integer can store.
b)Implementation of sizeof.
c)Used number of bits to find the max and min value
d)Use complement to find the max value of integer(complement 0 and reset the signed bit to get max value) All these questions were linked from 1 to other.

Q: Rotate integer n bits right.

Q: Two linked lists having a common node. Find the node.

Q: 1,2,4,6 and operators + - * / . Operators can be used any number of times. Write expressions to make 24 and 25

Q: 5,5,5,5,5 and any operators. Make 37.

Q: 2 cans of 10L each full with water. An empty can of 4L and another of 5L. move 2L to each of 4and 5 can.

Q: Reverse linked list.

Q: Few questions on output of C++ codes.

Q: A chess board 8X8 given(area 64 units). 31 slabs of 2X1 each(area 62 units). Arrange slabs on chessboard such that top-left and bottom-right corners are left empty.

Q: There are 100 prisoners. The jailor will make them stand in a row 1 after other, so that each person can see the people in front of him. The he will put caps of red and black color at random on head of each prisoner. There can be any number of red and black caps. The person telling the right color of his hat would survive, others dead. One person can speak one word i.e. the color of his hat.Before the activity the prisoners can think of some protocol to be followed so that max number can survive. No one would cheat. Decide the protocol that shd be followed.


Adobe Interview of Manmohan

Written test for DS and C paper has changed but Quantitative and Analytical are still the same.

DS Paper:
1) Nodes are given in order, make the BST for these nodes
2) Hash function was given had to find which numbers map to the same key
3) Using Boolean operators solve a boolean expression
4) LCA for a BST write code.
5) Base conversion from a 14-base to 7-base
6) Paranthesis matching problem which DS would be best and why
stack was the answer. (tree, stack, queue, linklist were choices)
7) Prefix expression was given had to find the value for given A and B
8) Dont remember
9) Dont remember
10)Some assembly lang program was given need to find whats the behaviour of the program
It was some recursive routine.

C paper:
1) Difference between 2 statments actually they were some pointer to function
2) int *i,*j;
i = (int*) 60;
j = (int*) 20;
printf("%d",i-j);
3) Middle node of link list
4) Missing number find in array in o(n) time number in the range 1-n-1
5) Gcd or 2 numbers
6) Reverse a doubly link list
7) Call statements for a function named crazy(int n, int a, int b)
void Crazy(int n, int a, int b)
{
if(n==0)
return;
Crazy(n-1, b+n, a);
printf("%d %d %d\n", n,a,b);
Crazy(n-1, b, a+n);
}
8) Find 2's compliment of a number which is given in string form
9) MACRO were defined for SUM(a, b) and MULT(a, b)
then printf the result of some expression formed by using these MACROs
10)
file1.c
int myarray[10];

file2.c
extern int* myarray;
void foo()
{
myarray[0] = 0;
}
What problems this program might have and under what conditions?


Technical Interviews

Round1:
1) char* ftoa(float f, int d);
d: number of digits after decimal place that needs to be printed
2) Minesweeper game discussed logic and strategies
3) Tower of Hanoi for N discs, What if the disks are not sorted
4) Max subarray sum problem

Round2:
1) Levelwise traversal
2) Virtual Destructor
3) Nth node from the end of the list
4) Mirror image
5) Power of 2
6) Puzzle a rectangle is given u take out a smaller rectangle from it.
Now divide the rectangle bigger one into 2 equal parts using a single straight line.
7) A mooon shape was given and using 2 lines needed to divide it into 6 parts.
8) Question on polymorphism and other basic question on c++.
9) Container class interfaces and all what all will u have.
10) Permutation and given an API that checks if the word is valid or not.

Round3:
1) 5 5 5 5 5 = 37 puzzle
2) Reverse a link list
3) Power of 2 or not
4) Count number of 1's set bit in an integer
5) Apple, Orange and Mix Puzzle
6) C++ questions tell the output of the program
7) Find repeated number in an array of size n, numbers in the range 1-n-1
8) 8 balls one of them is lighter than others find in 2 weighings
9) What is reference and pointer

Round4:
It was an HR round very long and interesting

Round5:
1) Stack implementation, implement a queue using stack this interface
2) Spiral printing of a matrix m*n
3) Some memory manager kind of thing discussion. Memory allocator and deallocator for efficiently using the memory.

Adobe Interview of Ruchi Sharma

****ROUND 1****

1) Reverse a linklist.

2) Find whether two given linklists of any length merge at a point or not.

3) Print binary representation of a given integer.

4) Code to find all permutations of a given string.

5) puzzle : 5 5 5 5 5 = 37 use any arithmetic operators on LHS to make 37 .

6) puzzle:
given : -20 = -20
to prove : -4=-5.
4-5 steps were given to prove this. I had to find which step was wrong.

7) puzzle : 5 bags each having balls of same weight except one bag. find the bag having the odd ball.

8) Two C++ questions..find output.


****ROUND 2****

1) Given an integer, write code to find max and minimum value it can store.The number of bytes of the integer
is also unknown and no lib func is to be used.

2) An array has numbers in unsorted order n no fix range.any number can be repeated any number of times.
Extract unique elements from the array.

3) 4 tumblers A, B , C , and D of max capacity 10ml,10ml,4ml and 5 ml milk respectively.
make 2ml each in C and D without losing milk.

4) Discussion regarding project.


****ROUND 3****

1) Given a number N.Write a code to Print all primes in the range 2 to N.Optimise it also.

2) Given an array having positive and negative numbers. Find a contiguous sequence having max sum.

3) HAT puzzle : A team of N players, where N is at least three, are randomly assigned hats that
are equally likely to be white or black, under conditions such that:

- Each team player can see the hats of the other team members, but cannot see their own hat.
- Team members cannot communicate in any way.
- The jailor will ask each prisoner the color of his hat.
- If he got wrong ans the prisoner would be killed.

Find the strategy followed by prisoners to minize no of deaths.


4) Discussion regarding project.

Friday, August 29, 2008

Trilogy Interview of Manmohan

Hi these are the question asked to me in Trilogy Interview.
Hope these questions help you too :D All the best :)


1st Round

Only postorder of bst given regenerate the tree
Approach
Code
Complexity
Optimization improve the order of ur solution


2nd Round

1) Spiral printing n*n matrix not m*n actually discussed for that also but coded for n*n only

2) LCA least common Ancestor

3rd Round

LinkList merging Y shaped find the common point or merging point
char array is given find the first repeating character in the array

eg. char a[ ] = "abcdcad"

return "a" here...not "c"

Reverse link list: Code and explanation of calls made
Test case : when llist contains a loop then it will fail then what will u do

1) Then find the loop

2) Remove the loop then reverse the list using this function

3) Camal Banana puzzle 4000 banana and 1000 km and 1000 banana max limit per trip
What is the maximum number of bananas u can take to the other side.
4) Pure virtual function

5) Sinlgeton class Implementation

6) Diameter of a tree: Code and Complexity


4th Round

1) 1-d array given find the sum of the elements between 2 indices say i and j in constant time
eg. a[] = "1 4 2 5 6 3"
and if i = 2 and j = 4 then it should return the sum 4+2+5 from the array in constant time .
U need to do some preprocessing on array for this
2) Now the same for a 2-d array. Now two indices are given say (i1,j1) and (i2,j2)
Find the sum of elements of the rectangle formed by these indices in constant time again do some preprocessing computation for this and return the result in constant time.
3) check IsBst() check if a binary tree is bst or not
do it in o(n) now
do it in o(n) with o(1) space complexity now
4) 2 candles each burns 1 hr Measure 45 minutes