Sie sind auf Seite 1von 4

1.

Given an array A of n numbers,compute an array B , such that


B[i]=product of all A[j]'s j!=i. In o(n) time, without using division operator.
2. Given a set of circles, find the smallest bounding circle which encloses all
the given circles.
3. Implement MemMove handling the address overlap case .
4. Design the structure of classes to represent expressions.
They may be binary,unary or just an operand.
5. Find the nth node in the inorder traversal, given a pointer to the root.
Do not use extra data field, static or global variables.
6. You are given 1 million numbers 32 bit integers and 2MB of Ram .
How do you sort them ? If given 4MB Ram , how do you sort them ?
7. How do you sort n telephone numbers in O(n) given infinite memory ?
8. (Good one :) )
There are n documents d1,d2,...dn. Each one is given a unique ranking from 1 to
n.
Design a new ranking function such that the new ranking should be less than Max(
di) - maximum ranking
the document di can be given(< Max (di)). The relative ranking should be maintai
ned if possible.
9. You are given 16 Billion 64-bit numbers. For a given number, find a number fr
om the given set such that
you can obtain the number from the given number by flipping its bits. Maximum nu
mbers of bits that
can be flipped are 3. Find the numbers which requires least number of flips. How
many number of total I/O accesses
are required. How much data is being trasfered. How do you decrease the I/O acce
sses.
10. How are vectors implemented (Arrays). Why is the array size doubled , instea
d adding some small quantity to it.
Explain the difference between the two approches.

My Interview consisted of two rounds :


These are questions asked:

1. Given a pointer to a node in a binary search tree, find the inorder successor
of that node (the node that will be visited next after this in an inorder trave
rsal). Assume that every node has a pointer to the parent(root->parent=-1)?
Ans:
Asked me to write the code for it.
t is the pointer
tree* inorder(tree *t)
{
If t->right!=NULL
search leftmost node in the right subtree.
else
current = t;
while(current->parent!=-1)
{
if(current==current->parent->left)
return current->parent;
current=current->parent;
}
return NULL;
}
I started of with wrong code ; he hinted the presence of bugs and finally write
the above one.

2. Given numbers from 1 to n, find the number of combinations of r numbers such


that no two numbers in a combination are consecutive. Find the recursive relatio
n and Write a program to do the same given a number n and r. How do u minimize s
pace in this case?

Ans: recursive relation : F(n,r)= F(n-2,r-1) + F(n-1, r)


Program:
I said using Dynamic programming - n x r matrix (array)

Compute values row after row , he suggested column-wise computation.


Space minimization : I couldn't come up with it first ,
then he suggested the example of fibonnaci number computation. I said
I said minimum required is n but he said it 2*n (I was wrong :) ).

3. Given a sentence , how do you reverse the order of words in it ?


Ans:
Reverse the entire array (sentence) and then individual words.

4. How do find rectangular intersection?


Ans: Bentley -ottmann algorithm . He asked me to explain it.

5. How do you find median of numbers given in two sorted arrays of size n.
Compare the elements at n/2 in each array
if equal : it is the median.
if not equal : recursive call for median of the half of array right to the small
er one
and half of the array left to the larger of the two.

6. Given 1000 (distributed)systems and 1 million numbers , how do you find the m
edian of those numbers? Every system has a set of numbers and they are not sorte
d.
Ans: Similar to the 'Select' algorithm
pick a pivot from one of them and send that pivot to other systems. They'll retu
rn the number of elements to the right and left of the pivot .

Accordingly , call the select depending on the number of elements less than (or
greator than) pivot .

7. Given a polygon and a point how do you find whether it lies inside the polygo
n ?
Ray - Scan algorithm : odd number of intersection - inside ; even - outside
8. SKyline problem. Given a set of intersecting rectangles (whose sides are para
llel to the axes and bottom edge rests on the x-axis), how do you find the upper
envelope of them.
Sort the horizontal edges (top edges of the rectangles) into an event queue and
insert them into a max heap based on their y- coordinates. Any changes to the ro
ot of the heap is stored(skyline) and delete the edges when u encounter the othe
r end of
the segment.

9. How do you determine whether two regular expressions generate same language ?
Compute the minimal DFA for the expressions and compare the corresponding states
and the transitions from them.

Das könnte Ihnen auch gefallen