Wednesday, April 29, 2009

Decho Interview of Sandeep Jain

Hi,

This is my Interview Experience at Decho, Hope its helpful... :)


Round 1: One hour Aptitude test

It contained the usual apti questions like
- pipe
- ratio proportion
- seating/arrangements
- % related
- speed distance

It seems easy with the captions but there were few really tricky ones.

These two were different:

There is only one correct soultion to the following, what is it?
A) Ans is A
B) Ans is A or B
C) Ans is C or D
D) None of this

How many questions have you solved correctly?
A) All of them
B) None of them
C) All of them except this one
D) Only this one




Round 2: 30 Minutes Technical written

5 questions we had to do any 3

1) Reverse a Link List
void reverse(node **head)

2) Count the number of leaves in a binary tree.
This question was not that clear it seemed as if they wanted to know minimum & maximum number of leaves in a Binary tree with N nodes.

3) Write a function to Reverse the words in a sentence.
void reverse_words(char *sentence, int sentence_length);

For e.g.
Input: This is a book
Output: book a is This


4) Given a Binary tree, write a modify function that replaces a nodes value with the sum of the values of its children.
void modify(node *root);

5) There is a string, and a pair, count the occurrences of this pair in this pair.
E.g.: String = "abceabcdefqw", Pair = "ab"
int count_pairs(const string &str, const string &pair);




Round 3: First tech interview

Q) Tell me something about yourself
Q) About the project in Trilogy, He only wanted a basic introduction of the project
Q) I have to maintain an integer which can be in two states, i = a or i = b.
i.e. i can have only these two values. Write a code that toggles this value of i from a to b or vice versa. Without using if, switch, for, while, do-while, ternary.
I gave a XOR solution, but then he said do not use any XOR either.

Q) Write a function to find the first non-repeating character in a given char array.

Q) There are three ants sitting at the vertices of an equilateral triangle. They can only move along the edges of the triangle. If all of them have equal speed and all of them start moving at the same time. What is the probability of collision of any two ants?

Q) I have a group of people standing in a matrix form (i.e. rows & columns) I select a person A who is the tallest of the shortest of every column,
person B who is the shortest of the tallest of every row.
Out of A & B who has the chances of being taller than the other.

Q) What are const functions?
Q) How do you make a member variable modifiable even if the object itself is const?
Q) What are the ways in which you pass arguments to a function? (call-by-value, call-by-reference) Give examples and explain the working.
Q) I gave an e.g of using int type arguments. So now he asked What if are dealing with objects?
Q) When are copy constructors called? write a sample copy constructor.
Q) What is a singleton class? Write a sample.
Q) Why do we use virtual destructors?
Q) Suppose you created a class, can you prevent your users from using destructors?
Q) What happens when you use a static variable in a function? What if we have multiple threads facing race condition for that static variable?
Q) Where is the data that is used by a process stored? (he wanted details of storage in terms of local variables, global, static, dynamically allocated ones)
Q) Write a fully functional Queue class.




Round 4: Second tech interview

Q) Started with the Trilogy-project. Asked for a detailed description. What the project is, how it works, what have I done till now?
What kind of bugs I fixed? What was the biggest challenge during internship? etc etc... I spoke everything I could recall at that time.
Q) Write a function that will convert a binary tree into its mirror image.
Q) There is an underground electric wire from city A to city B, The wire has broken at some point. The only way to check the wire at any point is to dig that place and then check whether it is broken or not. Give an efficient way to do it, so that our time & cost is minimal.
I gave a solution(think a little, its easy) then he said, what if do not know the distance, we only know that wire starts from city A, and that it is broken at some point.
Q) Prisoners on a staircase with either red/blue hats. The one who tells the correct colour lives or he dies. Its a famous puzzle.
Q) Pirates puzzle, 5 Pirates, have 100 bucks. They follow a hierarchy all 5 being at different levels. The superior one decides how to distribute the money. Then there is a poll among the five, if there are more than 50% votes against the distribution the top most pirate is killed. Then the distribution has to be made by the 2nd pirate in the hierarchy and so on. Assuming that all pirates are really smart, greedy, and want to live as well. How would the leader distribute it.
Q) In a village there are 100 people & everone has a strange disease, all those who have this disease have a halo over their head. If anyone comes to know that he has the disease(by looking at his halo or if someone else tells him) he dies the next morning. i.e. Awareness of disease leads to death. :P
A magician, in an attempt to save them, cast a spell over the entire village. Because of which "NO one shall see his own halo, and no one shall tell anyone else about their Halo" NOW the questio is, For many days will they live?



Round 5: Third tech interview

Q) Write a recursive function to compute the number of binary 1's & 0's both.
Q) Write a function that removes extraneous spaces from a string. For e.g.
Input: "I______am_____a______Boy"
Output: "I am a Boy"
Input: "______I_____am_____a____________Boy____"
Output: "I am a Boy"

I gave them the code, but they insisted my code to have a fatal bug. & I kept disagreeing, finally they said, its correct telling me that they forgot to see the last line of code (which handled null)

Q) Why do we need multi-threading on a single processor? (He wanted the concept of DMA & I/O devices)
Q) There are 6 boxes numbered 1,2,3,4,5,6. Box 1 contains infinite balls of 1 kg. Box 2 contains balls of 2 kg and so...
However one of the boxes contains defective balls. All balls have the same defect and thus there weight is different than the expected weight. For e.g. in Box 3 we have all balls weighing 8 kg instead of 3 kg.
Given an electronic scale so that measure accurate weights of each, In how many least weighings can you find out the defective box, how many balls will you will take out from the boxes?



Round 6: The F-2-F with the General manager of Decho

Initially she did not ask any questions she just explained how the company works, what the project is, how the current project works etc etc. Then she asked me what I did or didn't understand. If I would like to ask any questions to her. This all seemed pretty good. Cause she made it appear as if I was selected. She also explained how Decho is a part of EMC^2 (It was acquired by EMC^2)
Then she told me that the HR will meet me next.



Round 7: HR round

- Tell me something about yourself starting from your school, Please skip the technical details.
- What about your family, fathers business, siblings etc etc.
- How did you get into this IT field, you already have a family business?
- Who are the people you met today? (I told her that in sequence :P)
- From the time you came to our office till now, what new have you learned?
- What was the best experience in Trilogy?
- What was the worst experience in Trilogy?
- Why not Aricent? Why not Nagarro?
- Why Bangalore & not NCR?
- She asked some resume related stuff, as well.
- What your strength? Weaknesses?
- (I answered being short tempered as a weakness) then why do you think you get angry?
- Why do you think people get angry?
- Next she wanted me to ask her questions, as much as I wanted to?

I asked her the following:
-- What do you think I should or must improve on?
-- What are the office timings? I hope its not a school.
-- I asked her about EMC^2 & how does EMC^2 effect Decho. What about recession's effect on EMC and thus on Decho?
-- How does the appraisals work? (Cause she said its the task of manager to check on the performance)
-- If the compnay provides cab facility or accomodation?

There were sone questions related to compensation as well, which I am not listing here... :P :P

And thats it...
Through with it... :)

All The Best to all of you.

Friday, April 17, 2009

Amazon Interview of Varun Maini


Telephonic Interview :

1) Explain ur current company project.He wanted to know in depth, at each step he said , can we go into more details of implementation.
2) You are given a very huge string ,u have to beautify it.
beautify means that wherever there are multiple spaces / tabs repace it with single space.Whenever there is a full stop make the next char in Upper case,
no characters except the start of new line should be in upper case except when they are enclosed in single/double quotes,
U have to do this all in a single traversal and const space.
3) Implement a stack so that push,pop and max would take O(1) time.(gave 4-5 approaches)
4) Given a date as 2001/10/02 its a palendrom , find the palendrom date that occured just before this.


Round 1: (focused just on coding)

1) given an array find three numbers whose product is maximum.

(NOTE : looks easy but dont be fooled , there could be -ve nos too !!!!
gave 3-4 approaches , finally gave code for the approach taking O(n) time and const space)

2) Given a binary tree , convert it into a doubly linked list where the elements in DLL will be in same order as inorder traversal of the tree.

3) Given a sorted array , rotate it from a given Kth index in best possible manner

4) given a sorted array that is rotated find the index from which rotation happened ( O(logn) soln )


Round 2 : (focused on coding and DS )

1) given an i/p string AAABBCCCAA , o/p = A3B2C3A2 etc .. requirements : single traversal of string and const memory

2) give me a data structure such that if there could be values between 1-1000 then u could do the following operation in o(1) time :

insert(x) , delete(x), giveAnyElement()

where 'giveAnyElement()' will return any element present in the Data Structure.

U can assume that memory is no issue .. just concentrate on O(1) time .

(My soln : take a array[3][1000] array wherein
for each of the 'i' index :
array [0][i] = a int having value 0 or 1 , where 0 means element not present , 1 = element is present
array [1][i] = index of next value in the list
array [2][i] = index of previous value in the list

Basically u need to implement a doubly linked list on in an array and u are done :)

3) given a linkedList where each node has two pointer fields next and Random
where next points to the next node of linklist , while random could point to any node in LL
so create a copy of the linkList.


Round 3 : (focused on Algo,DS and coding)

1) given a NxM matrix , where each array entry is a character, write a code that will find all the words that can be formed using elements in a row, oolumn and diagonal

2) given a binary tree , each node apart from left and right has a tail pointer attached to it , where each tail should point to a node which would
come to the right of the current node , if a inorder traversal of tree is done.
So u have to devise a O(n) algo to find out which all nodes have their tail pointers set incorrectly.

3) given a huge string of size n (where n = about one billion ), there are m strings each k characters long u have to find out all the occurences of these m strings
in a single traversal of the big string.

(soln started from naive string matching, then kmp,then sorting the m strings and using buckets,then using binary trees, tries, hashing etc .. )


Round 4 : (focused on my ability to Design )

1) u have a function where there is an infinite loop thats running and in that loop , getRandomNumber() is called, at any point of time i should be able to track
the maximum, minimum, second max , sum , mean ,median etc of the nos.

Also i should have the flexibility that i can add more features , ex i can also add feature to find mode of the nos found so far

more importantly :a) i should have the flexibility to 'Remove' any feature as and when i want
b) i should be able to change the implementation of any of max, minimum methods without needing any change in my class


(My soln : after a good long discussion , i used Observer Design Pattern)

2) what is the diff between interface and abstract classes
give real world examples for them.

3) What do u know about JDBC , what is the purpose of the driver, when u do a preparedStatement.execute() then what all happens

4) Discuss the Collections API , what all interfaces and concrete classes does it provide , if u had to create ur own Varun-collections API then what all interface
and abstract classes would u provide

5) U have to design a database schema denoting the entire recruitment process , wherein storing info about candidates , interviewers , the interview results etc ..

Round 5 : (foucussed on Algo and how efficiently can i convert my algo to code)

1) given a NxM matrix where each row has elements in sorted order , and each column has element in sorted order , u have to find a given no in O(n) time and no extra space
ex :
1 4 10
3 6 11
4 7 15
find if 7 is present or not .

2) Given n sorted arrays merge them into a single sorted array

3) If i give u an N then ur code should give me the no of distinct binary trees possible with N nodes
ex i/p = 3 o/p = 5

4) once again went back to first question , now its given that all the arrays are increasing continously
ie
1 4 10
12 16 20
24 30 35 now find if a given x is present of not



Round 6 : (Focussed on HR,Data Strcuture , Algo)

1) whats the best thing about trilogy
2) if u have to change something in trilogy what would that be
3) biggest challenge u faced there
4) biggest accomplishment
5) Why amazon , there are 100 of companies out there ???

6) if u have to design the algo for searching that would be used for google , then what algo are u going to use.

7) extension of 6th : u have a huge file and u enter some key words , now u need to find the closest set of characters that enclose the entire set of keywords.

ex : let String Be "ABAACAAABXYABX....BXAC.." where these A,B,C... are words (not a single characters)
suppose user enters the keywords A,B,C then ur answer should be "BXAC"


Round 7 : (DS, Algo , OS, Puzzles)

1) what all have u read in OS. Can u describe features of any OS.

(I told lot of things that i had read in Galvin , then i started to describe UNIX , giving details about inode, the kind of scheduling algo it uses, singal
mechanism it uses ,system call mechanism , the dual mode operations , the access control of files, talked about (datablock,superblock,inodeblock,bootblock)
talked about its shell and how can its functionality be easily extended etc ... )

2) in amazon we have millions of customers daily , if we wanted to give some gift to the customer who buy 3 or more items during the last 7 days , what DS and Algo
are u going to use to store and retrive this info

3) There is a file that has N lines
where 'i' th line says : "There are exactly i lines in the file which are false"

ie .. There are exactly 1 line in the file which is false
There are exactly 2 lines in the file which are false
..
..
There are exactly n lines in the file which are false

now u have to find out which of these n lines are true.

4) given a village with demons and a sleeping man, The man is always sleeping ,never wakes up. Now a demon can eat the sleeping man , but after that
he will fall asleep , any demon can eat another sleeping demon.
If demons are very smart and would always choose to stay alive than to eat the man and risk their lives.
so if initially there are 65 demons and 1 sleeping man ,, what would happen in the village ???

Adobe Interview of Varum Maini

Written Exam :

C/C++ :-

Ques 1.
Write setnum(x,p,y,n)
Dennis Ritchie question : set the n bits starting from position p in x with rightmost n bits of y.

Ques 2.
Write a program to find the depth of Binary Tree

Ques 3.
In Binary Search code, reduce the number of comparisons in while loop from two to one. Write the code.

Ques 4.
Difference between char arr[] = "string" and char *arr = "string".

Ques 5.
Implement int **my2DAllocate(int rows, int columns); to allocate memory for 2D array and return the int ** pointer.

Ques 6.
What are bit fields. Give example, when they are used.

Ques 7.
What are data break points. When do we use them.

Ques 8.
Write code to evaluate ReversePolish.
Input : 123+*
Output : 6

Ques 9.
Hex no. is given in string for (0x or 0X optional). Write code to get the integer value.



Engineering Paper :

Ques1:
For a String s
Head(s)= first char of s
Tail(s) = all the chars of s except head

I.e. is s=”abcd” , head(s)=”a” , tail(s)=”bcd”

So given concat(Head(s),Head(tail(tail(s))) = “ac” , which of the following could be s

abcd , aabc,acac , aaac


Ques 2.
Binary Search tree is given. Print all the possible routes from root to leaf.

Ques 3.
Give a Data Structure to denote a polynomial when :
a) polynomial is dense
b) polynomial is sparse

Ques 4.
U have a file that is much bigger than RAM , give an algo to sort the file.

Ques 5.

Int power(int base,int n)
{
if(n==0)
return 1;
else
{
int x = power(base,n/2);
if(n%2==0)
{
return x*x;
}
else{
return x*x*base;
}
}
}

if I call power(5,12) then how many multiplications will take place ?


Ques 6.
P1 : read the file
P2 : modify the file

Show how will u synchronize the process so that modify can happen only when no one is reading the file. Using constructs

Enter Critical Section :
Exit Critical Section :
Wait Event :
Signal Event

Ques 7.
Given code that did bubble sort and sorted an array in decreasing order. An array is given in sorted order, u have to find out that if the above algo is run on it .. then how many times would two array values be swapped.


Ques 8.
Given two binary tree, how will u find that they are isomorphic (that is at each level they are equal or are mirror image of each other)

Ques 9.
A rectangle is represented by two points P1(x1,y1) and P2(x2,y2) representing lower left and upper right corner.

So given two rectangles , find if they intersect.



Interview 1 :

1) A date is represented as yyyy/mm/dd ex : 2001/10/02 .
Now observe that the above date is a palendrom, so find out the palendrom date which came just before the above date.
(Hint : September dosn’t have 31 days !!!! )

2) given two stings s1 and s2 , s1 has some characters at the end which are same as some of s2’s starting characters ..
so u have to concatenate the strings so that the repeated portion occurs only once.

Ex : S1 = “ ABCDEFGHIJK”;
S2 = “GHIJKXYZ”;

O/p = “ABCDEFGHIJKXYZ”

3) given a big string , u enable a person to underline some characters , for example some body had underlined characters 3-6 and 10-14 and so on ..
suggest a Data structure which can record this info effeciently and can accomodate new underlines .
NOTE : a new underline could lead to updation of records for ex consider a underline that starts from 5-8 .. then above set would become 3-8 and 10-14
NOTE : a new underline could lead to MERGING of records for ex consider a underline 4-13 .. this would lead to 3-14 in above set.

4) arr[2][3][2]={1,2,3,4,5,6,7,8,9,10,11,12};
what is value of arr,*arr,**arr,***arr, arr+1 ,*arr+1 ,**arr+1,***a+1

5) Given a no N, find all prime nos from 1 to N. using the fastest approach possible.

Now the answer i gave for this question left him speechless ..
He was basically just looking for the soln where i store all the previously encountered primes in an array and just keep dividing my no with them to find if its prime or not
But because of my maths background i gave a answer which uses Fermat's Theorm and proved much faster than above approach and no extra memory reqd.

After that soln he kind of felt overwhelmed and the interview was over :D



Interview 2 :

1) Given M sorted arrays , each having K elements , merge them into a big sorted array of size MK in most efficient manner possible.
(Hint :- Coreman Question : Use a Heap)

2) If u have to desing ur own Operating System , what mechanism are u going to use for ur file system .

(I started with using continous blocks to store file , this lead to external fragmentation ..
so next i told of using linked approach , where in each block i also keep address of next data block
next moved to FAT system...
Finally came up with an indexed approach , where first datablock just stored pointers to rest of data blocks)

3) Implement a stack such that push,pop and max and min are obtained in O(1)

4) given an array[1...N] which have elements from range 1-N they have elements that are repeated any no of times.
So give all the approaches u can come up for to find the nos that are repeated.

(first O(n^2) approach : brute force
then sort and find out
then use and extra array of size n
then use a bit vector of size n
no extra memory , whenever u encounter a no go to that index and make the value -ve ....
and another couple of really fundoo algos were given )

5) How will u create ur own C++ library.

(told that i will create my classes and place all my implementations in it. and provide a header file which having the class , macro and typedef declarations.
He then asked that what approach would u use to avoid mentioning all private and protected functions from the '.h' file
After about 5 - 10 mins of discussion .. i gave the correct answer .. that i will create a class which has all my private and protected funtions .. and in my
original class i will just add a POINTER to that class (Note : Pointer and not object as if i use an object then i have to give my second class's declaration too
and so will land up at square 1 )

6) Create a singleton class in C++


Interview 3 :

1) given a link list , find if its a palendrom or not.
(I gave one soln , then he asked me to code a recursive one )

2) There is a rectangular table , u and ur friends have identical coins , so u place a coin on table,then ur friend places one (no overlap allowed) , in the end
there would be no space left on the table and the person who is not able to place his coin on the table looses.
So device an algo such that if u place the first coin , u will always win .

(Basically place the coin at the center (point of intersection of diagonals), then wherever the friends places a coin, place a coin at its mirror image across the diagonal,
so for all his coins u are able to place a coin, hence cancelling his every move, but u have a coin extra at the center and hence in the end u will win)

3) In a party there is X, X's wife Y along with A,B,C,D,E and F (where b is a's wife , d is c's wife and f is e's wife). So ppl meet and handshakes take place , its given
a husband dosnt shake hands with his wife. In the End X asks every1 else the no of handshakes that they had .. and all give different Answers !!!!!!
IF its given that X shook hands with A. Then u have to find if Y shook hand with A / B / either of them / none of them

4) Applications of Heap, implement heapsort

5) function to generate permutations of a string ( he told me to assume that all characters in string are different)

6) being in line with prev question , he told me to come up with a Data structure that given a string , find all anagrams of string.


Interview 4:

1) given a no x , convert it to binary and store it into a char array and return.

(Looks simple, but is not .. basically u need to take care how much memory u need to allocate the array , then if u are returning , should u create a array
or use malloc , then how should the calling function accept it as char * p = fun() or char p[] = fun()

He then changed some lines of code and said now what will happen and so on ..)

2) given two very big files , each having around 1 billion lines , u have to print all the lines that are common to both files

(gave nearly 10 different approaches :
brute force , create a binary tree of one file and then keep searching elements of other file in it,sort one file and do binary search , sort both and compare top two and proceed ,
sort and place the strings in buckets , buckets then gave way to B trees , then hashing , break file into small mangagable chunks and then proceed etc etc ..)

3) what is virtual memory and how would u use it in the previous question

4) given a N X M matrix , find out the total nos of rectangles that can be there.


5)
int p = 0x6000;
int *q = &p;

fun(int *r)
{
*r = *q;
}
int main()
{
int a = 0x5000;
fun(&a);
printf(a);
}

here he asked the o/p. then he made the following change

he replaced the int * r with char ** r , then asked me what would be the o/p. This really confused me, but i figured out the ans in about 2 mins .
then he replaced the char ** r with char *r, this looks simpler than pervious case , but believe me .. this is the toughest ,

here when we do *r = *q this would then lead to storage of 0x6000 % 255 to be stored in *r
also there is now the case of Endianess, if machine is little Endian then r has changed the Least Significant Byte of a else the Most Significant Byte.


HR round :

1) ur marks in 10,12,grad and mca
2) ur ranks in all the above
3) what all companies did u sit in during campus placements , out of them in how many did u get selected
4) what was ur rank in DU's MCA enterance
5) what would ur boss say about u
6) What is the best thing about Trilogy and whats the worst
7) Package , how much expected
8) Whats ur worst habbit
9) How is ur rapport with ur team in trilogy
10) Give me 5 reasons that seperates u from others so that i should select u
11) How do u rate ur performance in trilogy on a scale of 1-10