Re: [algogeeks] Re: AMAZON: given col id, print col name in excel

2012-08-11 Thread yq Zhang
No. It's not base 26 at all. Given input 26, your code will return ba, but
the result should be aa. It's not equivalent to a number.

On Sat, Aug 11, 2012 at 2:57 AM, shiv narayan wrote:

> yes actually we have to print a,b,c..z instead of nos , so for that i have
> stored nos in character array  so only characters will be printed not nos
>
>
> On Sat, Aug 11, 2012 at 2:18 AM, yq Zhang  wrote:
>
>> @shiv, your code is correct go compute the base 26 number. However, this
>> question is not base 26 number obviously.
>>
>>
>>
>> On Wed, Aug 8, 2012 at 4:46 AM, shiv narayan 
>> wrote:
>>
>>> this is similar to conversion of no in base 26.( where digits are
>>> a,b,c,d...z) just think it like decimal to binary conversion here base is
>>> instead 26.
>>>
>>> char Carr[26]={a,b,c...z}
>>> i=0;
>>> int arr[];
>>> do
>>> {
>>> arrr[i++]=n%26;
>>> n/=2;
>>> }
>>> while(n) ;
>>> for(int i=n-1;i>=0;i--)
>>> cout<>>
>>> correct me if i am wrong.
>>> On Wednesday, 8 August 2012 12:56:56 UTC+5:30, ashgoel wrote:
>>>>
>>>> Imagine a sequence like this: a, b, c...z, aa, ab, ac...zz, aaa, aab,
>>>> aac aax, aaz, aba, abc... (Its same as excel column names). Given an
>>>> integer (n), generate n-th string from the above sequence.
>>>>
>>>> Best Regards
>>>> Ashish Goel
>>>> "Think positive and find fuel in failure"
>>>> +919985813081
>>>> +919966006652
>>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/algogeeks/-/Z3kYiTZi_F8J.
>>>
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Shiv Narayan Sharma
> Jt. Secretary CSI-DTU
> +919971228389
> www.jugadengg.com
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: AMAZON: given col id, print col name in excel

2012-08-10 Thread yq Zhang
@shiv, your code is correct go compute the base 26 number. However, this
question is not base 26 number obviously.



On Wed, Aug 8, 2012 at 4:46 AM, shiv narayan wrote:

> this is similar to conversion of no in base 26.( where digits are
> a,b,c,d...z) just think it like decimal to binary conversion here base is
> instead 26.
>
> char Carr[26]={a,b,c...z}
> i=0;
> int arr[];
> do
> {
> arrr[i++]=n%26;
> n/=2;
> }
> while(n) ;
> for(int i=n-1;i>=0;i--)
> cout<
> correct me if i am wrong.
> On Wednesday, 8 August 2012 12:56:56 UTC+5:30, ashgoel wrote:
>>
>> Imagine a sequence like this: a, b, c...z, aa, ab, ac...zz, aaa, aab,
>> aac aax, aaz, aba, abc... (Its same as excel column names). Given an
>> integer (n), generate n-th string from the above sequence.
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/Z3kYiTZi_F8J.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] longest continuous sequence

2012-08-10 Thread yq Zhang
def long_continuous_seq(A):
ls = {}
result = (0,0)
for x in A:
if not x in ls:
left = ls[x - 1] if (x - 1) in ls else 0
right = ls[x + 1] if (x + 1) in ls else 0
if left + right + 1 > result[1] - result[0]:
result = (x - left, x + right)
ls[x] = left + right + 1
ls[x - left] = left + right + 1
ls[x + right] = left + right + 1
return result


On Sun, Aug 5, 2012 at 11:40 AM, payal gupta  wrote:

> Find the longest
> subarray which consists of numbers that can be arranged in a continuous
> sequence.
> For ex- {4,5,1,5,7,6,8,4,1}
> output-{5,7,6,8,4}.Find the longest.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/MuACHn8S8vUJ.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: [Amazon]

2012-07-26 Thread yq Zhang
@ankush, there can be multiple probable 2D array according to your
definition.

On Wed, Jul 25, 2012 at 7:01 AM, ankush sharma  wrote:

> Hi,
>
> I think the following approach will work.
> 1. As the array is sorted in all three directions, assume the 3D array to
> be a stack of rectangular arrays or 2D arrays.
> Searching in a 2D array of size M*N is trivial - time complexity O(m +
> n). Provided that the 2D array is sorted, both row and column wise
>
> 2. Now the problems comes down to which 2D array to search. For this we
> can use binary search on the 3d dimension in the following way -
> - We know that if an element lies in a sorted 2D array, it value must
> lie between the top-left element arr[0][0] and bottom right element
> arr[m-1][n-1].
> - Perform a binary search to find the probable rectangle (2D array) in
> which the given element lies. Let say the 3rd dimension is r. Check for the
> r/2th rectangle.
>   If the top-left element and the bottom-right element of the r/2 2D
> array > element, search the lower half in the 3rd dimension.
>   If the top-left element and the bottom-right element of the r/2 2D
> array < element, search the upper half in the 3rd dimension.
>   If the top-left < element and the bottom-right element > element,
> this should be the probable 2D array.
>
> 3. Search for the 2D array find in the 2nd step, if element is found -
> Search is successful--:) else element doesn't exist
> If no such 2D array is present as in the 2nd step, the element doesn't
> exist
>
> Worst case complexity for an arr[l][m][n] - O(m+n)*logl
>
> The invariant in this approach is that for a 2D array, all its elements
> are >= the previous 2D arrays. So if the minimum element of a 2D array i.e
> the top-left
> element is smaller than element to be searched, there is no need to search
> for the earlier arrays. Similar is the case for greater than case.
>
> On Friday, July 20, 2012 11:24:08 AM UTC+5:30, Sakshi Agrawal wrote:
>>
>> How will you search an element in sorted 3D Array ?  ( Sorted in all the
>> 3 directions )
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/XSZVSbXF2H8J.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Median of 2D matrix

2011-11-08 Thread yq Zhang
Vikas,

The cost of removing elements from the matrix is O(N) it self. So by
removing N^2/2 elements, the complexity of your algo should be N^3. However
there are well-known algo for median in O(N) time in this case O(N^2)
*because there are N^2 elements.




On Tue, Nov 8, 2011 at 6:58 AM, vikas  wrote:

> Gene,
> we are not creating heap here but using the sorted matrix as heap
> itself.
> so use same logic of removing items from heap , in this case you have
> either right/bottom to reconstruct the structure. removing N^2 /2
> items will give you the median.
>
> On Nov 7, 11:03 pm, Gene  wrote:
> > Can you explain how a heap helps get the answer?  Just to put the
> > elements in a heap requires O ( N^2 log (N) ) time.
> >
> > On Nov 7, 4:12 pm, vikas  wrote:
> >
> > > I think the best we can have is nlogn solution with the heap approach.
> >
> > > On Nov 6, 10:27 pm, Dave  wrote:
> >
> > > > @Mohit: Here is a counterexample:
> >
> > > > 10  1152  53  54
> > > > 20  21  112 113 114
> > > > 30  31  122 123 124
> > > > 40  41  132 133 134
> > > > 50  91  142 143 144
> >
> > > > The median is 91, and it is not on the anti-diagonal.
> >
> > > > Dave
> >
> > > > On Nov 6, 3:11 am, mohit verma  wrote:
> >
> > > > > @Gene
> > > > > As i said in my earlier post right to left diagonal partitions the
> martix
> > > > > into 2 equal number of elements. So now the median must be in this
> > > > > diagonal. Now our focus is on finding median of this diagonal only.
> > > > > I think this works fine. Can u give some test case for which it
> fails?
> >
> > > > > On Sun, Nov 6, 2011 at 3:02 AM, Gene 
> wrote:
> > > > > > Unfortunately this isn't true. See the example I gave earlier:
> >
> > > > > > 1 2 3
> > > > > > 2 4 5
> > > > > > 3 4 6
> >
> > > > > > Thje median is 3.
> >
> > > > > > 1 2 2 3 >3< 4 4 5 6
> >
> > > > > > Niether one of the 3's lies on the diagonal.
> >
> > > > > > When you pick any element P on the diagonal, all you know is that
> > > > > > anything to the right and downward is no less than P and
> everything to
> > > > > > the left and upward is no greater.  This leaves the upper right
> and
> > > > > > lower left rectangles of the matrix unrelated to P.
> >
> > > > > > On Nov 5, 3:51 am, ankit agarwal 
> wrote:
> > > > > > > Hi,
> >
> > > > > > > I think the median will always lie on the diagonal
> > > > > > > a[n][1]  a[1][n]
> > > > > > > because the elements on the LHS making the upper triangle will
> > > > > > > always be less than or equal to the elements on the diagonal
> > > > > > > and the RHS, elements in the lower triangle will be greater
> than or
> > > > > > > equal to them.
> >
> > > > > > > so sort the diagonal and find the middle element, that will be
> the
> > > > > > > median.
> >
> > > > > > > Thanks
> > > > > > > Ankit Agarwal
> >
> > > > > > > On Nov 5, 1:29 am, Gene  wrote:
> >
> > > > > > > > Here's an idea.  Say we pick any element P in the 2D array A
> and use
> > > > > > > > it to fill in an N element array X as follows.
> >
> > > > > > > > j = N;
> > > > > > > > for i = 1 to N do
> > > > > > > >   while A(i, j) > P do
> > > > > > > >  j = j - 1;
> > > > > > > >   end;
> > > > > > > >   X(i) = j;
> > > > > > > > end;
> >
> > > > > > > > This algorithm needs O(N) time.
> >
> > > > > > > > The elements of X split each row with respect to P. That is,
> for each
> > > > > > > > i = 1 to N,
> >
> > > > > > > >   A(i, j) <= P if 0 < j <= X(i),A(i,j) > P if X(i) < j
> <= N.
> >
> > > > > > > > Now the strategy is to create two length N arrays a =
> [0,0,...0]; and
> > > > > > > > b = [N,N,...]. We'll maintain the invariant that a[i] <
> Median <= b[i]
> > > > > > > > for some i.  I.e, they "bracket" the median.
> >
> > > > > > > > We define functions L(a) = sum_i( a(i) ) and R(b) = sum_i( N
> -
> > > > > > > > b(i) ).  These tell us how many elements there are left and
> right of
> > > > > > > > the bracket.
> >
> > > > > > > > Now reduce the bracket as in binary search:  Guess a value
> P, compute
> > > > > > > > X.  If L(X) >= R(X), set b = X else set a = X.
> >
> > > > > > > > Keep guessing new P values in a way that ensures we reduce
> the number
> > > > > > > > of elements between a and b by some fixed fraction.  If we
> can do
> > > > > > > > that, we'll get to 1 element in O(N log N) time.
> >
> > > > > > > > The remaining problem is picking good P's. Certainly the
> first time is
> > > > > > > > easy. Just take A(N/2, N/2). This has approximately (at
> least) N^2/4
> > > > > > > > elements larger than it and N^2/4 smaller due to the sorted
> rows and
> > > > > > > > columns.  This is what we need to get O(N log N) performance.
> >
> > > > > > > > But after the first split, things get trickier. The area
> between a and
> > > > > > > > b takes on the shape of a slash / /, so you can't just pick
> a P that
> > > > > > > > moves a and b together by a fixed fraction of remaining
> elem

Re: [algogeeks] Re: Searching In a large file

2011-10-29 Thread yq Zhang
Given the SSN number is 9 digit number, the total space of possible numbers
are 1000million. So I think Dave's solution works.


On Sat, Oct 29, 2011 at 8:47 AM, bharat b wrote:

> @Dave
> Your solution works if the total no.of records(ssn numbers) is 1000
> million.
> But the question states that there are only 300 million numbers.
>
> I think some modification is needed to your answer.
> Correct me if i am wrong.
>
>
>
> On Fri, Oct 28, 2011 at 2:04 AM, Dave  wrote:
>
>> @Shiva: Using an integer array a[10], initialized to 0, read
>> through the file and for each number n, increment a[n%10]. At the
>> end of the file, find any k such that a[k] != 1. Then read through
>> the file again. For any number n such that n%10 == k, set a[n/
>> 10] = -1. At the end of file, find any j < 1 such that a[j] >=
>> 0. Then 10 * j + k is a number that is missing from the file.
>>
>> Dave
>>
>> On Oct 27, 10:25 am, "shiva@Algo"  wrote:
>> > Given a file containing roughly 300 million social security
>> > numbers(9-digit numbers), find a 9-digit number that is not in the file.
>> > You have unlimited drive space but only 2megabytes of RAM at your
>> > disposal.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: print vertical sums of a binary tree

2011-10-19 Thread yq Zhang
You should use a doubly linked list instead of any sort of array. All the
operation on the data structure you need are goto next/prev and insert
front/end.

Yunqiao

On Wed, Oct 19, 2011 at 6:40 AM, monish001  wrote:

> I think it might done using function of following prototype:
> void func(node* root, deque& d, const deque::iterator& it);
>
> I will add left child's value in it-1 if exists else create new...
> similarly for right child.
> and call the same function for each of the children to explore
> further..
>
> Monish
>
> On Oct 15, 11:57 pm, SUMANTH M  wrote:
> > Hi,
> >
> >A binary tree is given we need to print vertical sums of nodes. for
> > example
> >
> >   12  34 5
> >
> >   |  |   5| |
> >   |  | / |   \ | |
> >   |  |   /   |8 |
> >   |  | / |   / |\|
> >   |  4  |/|   10
> >   |/ |  \9| |
> >   |  /   |  \  | |
> >   7 |  6   |
> >   |  |  |  | |
> >   |  |  |  | |
> >   ---
> >   7 4 20   8   10
> >
> >  Here we need to print sum 7,4,20,8,10.
> >
> > -Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Amazon Interview question

2011-02-07 Thread yq Zhang
@above, "if initial position=final position or the final position was
empty,then choose the next element(element next to the initial position) as
current element"

How do you guarantee when you move to the next element, the next element is
not already processed? Otherwise, you will double process on element.



On Mon, Feb 7, 2011 at 9:36 AM, jalaj jaiswal wrote:

> algo in more detail :-o
>
> if the array is numbered from 0..(2n-1)
>
> i= initial position of int/char
> f= final position of int/char
>
> if (i < (2n-1)/2) #for integer
> f = i+i
> else #for char
> f = i - ((2n-1)-i)
>
> so iterate through the array in the following way
>
> choose first element
> determine it final position
> put the element in the final position
> the next element to be processed is the original element in the final
> position
> if initial position=final position or the final position was empty,then
> choose the next element(element next to the initial position) as current
> element
>
> stop when last element has been processed.
>
> eg
> 1234abcd
> current = 1
> i = 0
> f = 0+0 = 0
>
> i=f
> so current= next element= 2
> i=1
> f=1+1=2
> put 2 in 2nd position
> 1-24abcd
>
> current element = original element in 2nd position = 3
> for 3
> i = 2
> f=2+2=4
>
> so put 3 in 4th position
> 1-243bcd
> current =a
> i=4
> f=(i - ((2n-1)-i) = (4-(7-4)) = 1
> 1a243bcd
>
> now final position was empty
> so next element = intital position +1
> = intitial position of a +1 =
> 4 +1 = 5
>
> current = b
> processing in a similar way
>
> 1a2b3-cd
> current = 4
> 1a2b3-4d
> current = c
> 1a2b3c4d
> current = d
> 1a2b3c4d
>
> processed last element so stop
>
>
>
> can't explain more better :-o
>
>
> On Mon, Feb 7, 2011 at 10:59 PM, Manmeet Singh wrote:
>
>> thr is some error in algo
>>
>>
>> On Mon, Feb 7, 2011 at 10:48 PM, abc abc  wrote:
>>
>>> I would like to have pseudo  for this .
>>>
>>> On Mon, Feb 7, 2011 at 11:12 AM, jalaj jaiswal <
>>> jalaj.jaiswa...@gmail.com> wrote:
>>>
 A very common interview question

 let the array be from 0 to 2n-1

 now,

 every element of array has its initial position and final position..
 start from beginning
 if the elemnt you r processing is the first half of array then f=i+i;
 else f=2*i-(2n-1);
 replace the elemnt at final position with the initial element .. now
 next elemnt to process will be oroginal elemnt at final position
 if the final position is empty or the same position then process next
 element to the initial position.
 do until you process the last element.

 inplace with O(n).


 On Mon, Feb 7, 2011 at 8:32 AM, may.I.answer 
 wrote:

> If  [a1,a2,a3...,an,b1,b2...bn] is given input change this to
> [a1,b1,a2,b2.an,bn]
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


 --
 With Regards,
 *Jalaj Jaiswal* (+919019947895)
 Final Year Undergraduate,
 IIIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> With Regards,
> *Jalaj Jaiswal* (+919019947895)
> Software developer, Cisco Systems
>
> Final Year Undergraduate,
> IIIT ALLAHABAD
>
>   --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because yo

Re: [algogeeks] Re: Amazon interview quesiton

2011-02-06 Thread yq Zhang
but the tree can be created from a preorder walk is more than 1 right? so
the question only ask for 1?
On Feb 6, 2011 7:31 AM, "jalaj jaiswal"  wrote:
> My solution in more detail (in words ):-
>
> start from the end if you get an L
> make a node with data L and push its pointer in stack,
> if you get a M pop two elements from stack
> make them left and right children of M and then push
> back m's pointer to stack(if stack is empty then stack returns NULL when
> popped)
>
> at the end root is on the top :>
>
>
>
> On Sun, Feb 6, 2011 at 6:36 PM, bittu  wrote:
>
>> @anurag
>>
>> Good solution dear.
>>
>> Thanks
>> Shashank
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> With Regards,
> *Jalaj Jaiswal* (+919019947895)
> Final Year Undergraduate,
> IIIT ALLAHABAD
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Amazon Again

2011-01-29 Thread yq Zhang
can you prove it?
On Jan 29, 2011 6:38 PM, "Wei.QI"  wrote:
>
> Starting with any pump A, try to finish the circle, if at pump B that can
not reach pump B+1, it means all pumps from A to B can not finish the circle
(it will go broke at pump B), then just start with B+1. After go through all
the pumps start from some pump, we got an answer. if we go back to pump A
and later, still can not find an answer, there is no answer.
>
> On Sat, Jan 29, 2011 at 4:38 AM, sankalp srivastava <
richi.sankalp1...@gmail.com> wrote:
>>
>> I'm sure you have misstated the problem statement
>>
>> just find out the total path length and return the first petrol pump
>> which gives you the required milage
>> go greedy
>>
>> On Jan 28, 5:09 pm, bittu  wrote:
>> > There are N petrol pumps along a circular path. Every petrol pump
>> > gives some amount of fixed petrol. Need not to be unique and in no
>> > particular order means it is random. We have a car and we need to find
>> > a petrol pump which can provide so much of petrol that we can take a
>> > full of the circle. Mileage of car is fixed.
>> > Distance between adjacent petrol pumps are given.
>> >
>> > Thanks & Regards
>> > Shashank
>>
>> --
>> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
>> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C++ Doubt

2011-01-20 Thread yq Zhang
The reason is simple. The same thing happen in other language such as JAVA.
You can convert Derived class to Base class but you can't convert Derived[]
to Base[]. The reason is, if your Base class has two derived classes D1, D2.
They can exist in Base[] because D1, D2 are valid Base instances. While you
doing converting from Base[] to D1[], it's not possible, because in Base
there are other D2 instances. To avoid these common mistakes, converting
from Derived[] to Base[] it not allowed.

Yq

On Thu, Jan 20, 2011 at 5:54 AM, Decipher  wrote:

> When we can convert Derived* to Base* then why can't we convert Derived**
> to Base** ??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Find duplicate element in an array

2011-01-16 Thread yq Zhang
@Dave, your algorithm is a dijkstra cycle finding algo. It requires the
function to have only ONE SINGLE cycle in the transition function. However,
the transition function for the array could have several cycles. How could
you find the duplicate? Can you elaborate more on your solution? Maybe I
just didn't understand your solution.

BTW, if it's guranteed the number is between 1...n-2. The simpleset approach
is SUM(array) - SUM(1...n-2)

Thanks

Yq


On Sun, Jan 16, 2011 at 10:25 AM, Dave  wrote:

> Okay. Here is a further exposition of the solution. It took me a while
> to remember where I had used it before.
>
> i = n
> j = n
> do while not (i = j)
>i = A(A((i))
>j = A(j)
> end
> /* Now a=b can be reached at either 2k or k steps from n, */
> /* where k is some integer between 1 and n. */
> i = n
> do while not (i = j)
>i = A(i)
>j = A(j)
> end
> print a
>
> Dave
>
> On Jan 16, 11:57 am, juver++  wrote:
> > @Dave
> > Cycle finding algo (Floyd's, Brent's) can be applied only for the
> iterated
> > function values.
> > This means: f(x0) = x1; f(x1) = x2 and etc.
> > Suppose we have the following array: 1 2 3 2 4. Value 2 have two
> different
> > transitions.
> >
> > Clarify your proposed method if it needs additional observations.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-09 Thread yq Zhang
Then it is O(n) worst case. While juver's algo is amortized constant time in
worst case.
On Jan 9, 2011 10:26 PM, "SVIX"  wrote:
> The only operation for which this solution doesn't have constant time
> (variable based on number of items in the list) is for 'delete' and
> that too when the minimum item is deleted. For all other cases, delete
> is constant as well... For delete in those special cases, time is
> O(n)...
>
> On Jan 9, 10:19 pm, SVIX  wrote:
>> I think you misunderstood my solution...
>>
>> There's no "min value for each node" here... The queue class i propose
>> will look like this...
>>
>> public class MyQ
>> {
>>   private int? currentMin; //nullable current minimum val in the
>> queue
>>   private LinkedList itemsList;
>>
>>  //constructor and init stuff...
>>
>>   //all insert/delete methods, front, rear etc,...
>>   //one example set of insert and delete pseudocode
>>   public void Insert(int i)
>>   {
>>   if( currentMin == null || currentMin > i )
>>currentMin = i;
>>
>>   itemsList.Add(i);
>>   }
>>
>>   public int Delete()
>>   {
>>var itemToReturn = itemsList.First.Value;
>>itemsList.RemoveFirst();
>>
>>if(itemToReturn == currentMin)
>>  RecomputeAndStoreMin(); //A private method that'll
>> find and store min in O(n) time
>>
>>return itemToReturn;
>>   }
>>
>>   public int GetMinValue()
>>   {
>>  If(currentMin == null)
>> throw new InvalidOperationException();
>>  return currentMin;
>>   }
>>
>> }
>>
>> On Jan 9, 11:42 am, juver++  wrote:
>>
>> > When you remove element from the front of queue, you should update min
value
>> > for all remaining nodes.
>> > So it's linear.
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-08 Thread yq Zhang
When you push into stack2, you have to recompute the min value. So after you
push into stack2, it will be:

(6,6),(3,3),(4,3),(2,2)

On Thu, Jan 6, 2011 at 6:34 PM, sourav  wrote:

> @Juvier, @yq Zhang
>
> In your approach, when you are asked pop_front() you keep popping from
> one stack and pushing them to another and then from the other pop the
> top element. What happens is this top element happens to have been the
> Min element?Example
>
> stack1 {(2,2),(4,2),(3,2),(6,2)} (a,b) = ( element, min)
>
> then you are asked pop_front(), you push to another stach like below
>
> stck2: {(6,2),(3,2),(4,2),(2,2)}.
>
> Then you remove (2,2)! Ok. But all elements in your stack2 still say
> "2" is the min element. But "2" is no more in the "queue" (or for that
> matter in the stacks we are using).
>
> On Jan 4, 9:07 am, yq Zhang  wrote:
> > @sourav,
> >
> > As Juvier++ pointed out, it's an **amortized** O(n) algorithm. That's
> > because each element can be at most popped twice.
> >
> > Thanks
> > Yq
> >
> > On Mon, Jan 3, 2011 at 11:20 AM, sourav  wrote:
> > > @yq Zhang,
> >
> > > To pop if you are going to "pop all from first stack and push into the
> > > second stack", then does your operation remain "constant time"? Please
> > > note that we need constant time implementation for the 3 functions
> > > pop_front, push_rear and get_min(). Goint by your approach, not all of
> > > them are constant time.
> >
> > > Thanks,
> > > Sourav
> >
> > > On Jan 3, 9:44 pm, yq Zhang  wrote:
> > > > Push into one stack. When pop first pop all from the first stack and
> push
> > > > into the second stack. Then pop from the second stack
> > > >  On Jan 3, 2011 7:42 AM, "MOHIT "  wrote:
> >
> > > > > if only two stack are used but how pop_front is get?
> >
> > > > > suppose if element comes in order
> >
> > > > > 12 15 4 3 7 20
> > > > > then in min queue
> > > > > 1. 12 (12)
> > > > > 2. 12 12 (12,15)
> > > > > 3. 12 12 4 (12,15,4)
> > > > > 4.12 12 4 3 (12,15,4,3)
> > > > > 5.12 12 4 3 3 (12,15,4,3,7)
> > > > > 6.12 12 4 3 3 3 (12,15,4,3,20)
> >
> > > > > we can get min in constant by pop of stack but how pop front will
> work
> > > > using
> > > > > two stack only in constant time?
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> >
> > > > "Algorithm Geeks" group.> To post to this group, send email to
> > > algoge...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> >
> > > > algogeeks+unsubscr...@googlegroups.com
> 
> >
> > > 
> 
> >
> >
> > > > .> For more options, visit this group at
> >
> > > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algoge...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com
> 
> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Find a specific number in a special matrix.

2011-01-05 Thread yq Zhang
Thanks for sharing! It's good to know the data structure.

On Wed, Jan 5, 2011 at 9:10 AM, juver++  wrote:

> Other useful information about this structure is 
> here.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-05 Thread yq Zhang
That's a big save of space!
On Jan 5, 2011 9:03 AM, "juver++"  wrote:
> Good point. Right.
> But we can avoid first stack of such structure, having separate variable
> (Minimum) for this.
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Find a specific number in a special matrix.

2011-01-05 Thread yq Zhang
Either x is greater or less than the middle vale you have to search 3
quardant.  Because the value could be in bottom left or top tight.
On Jan 5, 2011 7:14 AM, "ADITYA KUMAR"  wrote:
> @ankit thanks for correcting
> @naveen yeah that will make it more precise
>
> On Wed, Jan 5, 2011 at 7:51 PM, Ankit Babbar wrote:
>
>> @ Aditya: Mac's Solution works correctlyfor your example:
>>
>> Start from 24(top right)..24>5: go left; 9>5: go left; 1<3: go
>> down; 2<3:go down: 3 found..:)
>>
>>
>>
>>
>> On Wed, Jan 5, 2011 at 7:37 PM, Naveen Kumar wrote:
>>
>>> I think if x < a[n/2][n/2] than we need to search in 1st quadrant
>>> otherwise in others.
>>>
>>>
>>> On Wed, Jan 5, 2011 at 7:20 PM, sourabh jakhar wrote:
>>>
>>>> aditya solution is correct
>>>> it is a standard question of young tabuleau
>>>> it is complexity is log(n)
>>>>
>>>>
>>>> On Wed, Jan 5, 2011 at 6:52 PM, ADITYA KUMAR wrote:
>>>>
>>>>> @MAC
>>>>> ur solution is wrong
>>>>>
>>>>> 1 9 24
>>>>> 2 12 33
>>>>> 3 16 49
>>>>>
>>>>> search for 3
>>>>>
>>>>>
>>>>> O(logn) solution
>>>>> let the matrix be A[][] and number to be searched is x
>>>>> divide the array from middle in 4 parts lets say it four quadrants
>>>>> now check if x>A[n/2][n/2] search in bottom right quadrant
>>>>> if x>>>>
>>>>> On Sat, Dec 25, 2010 at 8:25 AM, yq Zhang wrote:
>>>>>
>>>>>> Suppose you have a matrix n*m. each column and row of the matrix is
>>>>>> already sorted. For example:
>>>>>>
>>>>>> 1,2,3
>>>>>> 2,3,4
>>>>>> 4,5,6
>>>>>>
>>>>>> All 3 rows and 3 columns of above matrix are sorted. How to find a
>>>>>> specific number in the matrix?
>>>>>> The trivial O(nlogm) solution is to use binary search for all rows. I
>>>>>> am looking for better solution.
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algoge...@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> algogeeks+unsubscr...@googlegroups.com

>
>>>>>> .
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Regards
>>>>> Aditya Kumar
>>>>> B-tech 3rd year
>>>>> Computer Science & Engg.
>>>>> MNNIT, Allahabad.
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algoge...@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com

>
>>>>> .
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> SOURABH JAKHAR,(CSE)(3 year)
>>>> ROOM NO 167 ,
>>>> TILAK,HOSTEL
>>>> 'MNNIT ALLAHABAD
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
Groups
>>>> "Algorithm Geeks" group.
>>>> To post to this group, send email to algoge...@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com

>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> Cheers
>>> Naveen Kumar
>>>
>>> --
>>> You received this message because you are subscribed to the Google
Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com

>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Regards,
>> Ankit Babbar
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com

>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards
> Aditya Kumar
> B-tech 3rd year
> Computer Science & Engg.
> MNNIT, Allahabad.
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-05 Thread yq Zhang
I think both of them should provide min function? When you call getmin you
should use min value of the two min from both stack?
On Jan 5, 2011 8:10 AM, "juver++"  wrote:
>
> only 2 stacks, one of them (or both...) should provide functionality for
retrieving minimum.
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: XOR Rounds

2011-01-04 Thread yq Zhang
I think 500*500*500 is only 125M. It is not that bad?




On Tue, Jan 4, 2011 at 1:39 PM, juver++  wrote:

> Your matrix has n*n dimensions. So to multiply it, you need to do O(N^3)
> operations which is too slow for N=500. There is similar approach with a
> vector multiplication instead of your idea. Btw, it is reached from the same
> algorithm.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: XOR Rounds

2011-01-04 Thread yq Zhang
XOR is associative and commutative. So it's similar as "+" operator. First
turn the array into a n*1 vector. Each round of the operation could be
interpreted as a transition matrix A*vector.
For example, suppose you have a 4 elements array (a,b,c,d )intially, then
one round of operation could be interpreted as:

|1  1  0  1 || a |
|1  1  1  0 || b |
|0  1  1  1 |*   | c |
|1  0  1  1 || d |

When doing the matrix multiply, replace + as XOR replace value multiply as
exponential. For example, a+b in the matrix operation should be a XOR b.
while 3*a should be interpreted as a XOR a XOR a.
Thus the question is equivalent to find out A^k * (initial vector). You can
compute A^k easily in logk time.

Thanks

Yq



On Tue, Jan 4, 2011 at 12:16 PM, juver++  wrote:

> There may be long periods. So another approach should be applied.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-03 Thread yq Zhang
@sourav,

As Juvier++ pointed out, it's an **amortized** O(n) algorithm. That's
because each element can be at most popped twice.

Thanks
Yq

On Mon, Jan 3, 2011 at 11:20 AM, sourav  wrote:

> @yq Zhang,
>
> To pop if you are going to "pop all from first stack and push into the
> second stack", then does your operation remain "constant time"? Please
> note that we need constant time implementation for the 3 functions
> pop_front, push_rear and get_min(). Goint by your approach, not all of
> them are constant time.
>
> Thanks,
> Sourav
>
> On Jan 3, 9:44 pm, yq Zhang  wrote:
> > Push into one stack. When pop first pop all from the first stack and push
> > into the second stack. Then pop from the second stack
> >  On Jan 3, 2011 7:42 AM, "MOHIT "  wrote:
> >
> > > if only two stack are used but how pop_front is get?
> >
> > > suppose if element comes in order
> >
> > > 12 15 4 3 7 20
> > > then in min queue
> > > 1. 12 (12)
> > > 2. 12 12 (12,15)
> > > 3. 12 12 4 (12,15,4)
> > > 4.12 12 4 3 (12,15,4,3)
> > > 5.12 12 4 3 3 (12,15,4,3,7)
> > > 6.12 12 4 3 3 3 (12,15,4,3,20)
> >
> > > we can get min in constant by pop of stack but how pop front will work
> > using
> > > two stack only in constant time?
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> >
> > "Algorithm Geeks" group.> To post to this group, send email to
> algoge...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> >
> > algogeeks+unsubscr...@googlegroups.com
> 
> >
> > .> For more options, visit this group at
> >
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-03 Thread yq Zhang
Push into one stack. When pop first pop all from the first stack and push
into the second stack. Then pop from the second stack
 On Jan 3, 2011 7:42 AM, "MOHIT "  wrote:
> if only two stack are used but how pop_front is get?
>
> suppose if element comes in order
>
> 12 15 4 3 7 20
> then in min queue
> 1. 12 (12)
> 2. 12 12 (12,15)
> 3. 12 12 4 (12,15,4)
> 4.12 12 4 3 (12,15,4,3)
> 5.12 12 4 3 3 (12,15,4,3,7)
> 6.12 12 4 3 3 3 (12,15,4,3,20)
>
> we can get min in constant by pop of stack but how pop front will work
using
> two stack only in constant time?
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations.

2011-01-02 Thread yq Zhang
keep min for stack is easy. just use another stack to keep the min for each
top.

Sent from Nexus one
On Jan 2, 2011 11:43 AM, "Anuj Kumar"  wrote:
> @juver++ how will implwment find_min() function?
>
> On Sun, Jan 2, 2011 at 2:33 PM, juver++  wrote:
>
>> Simulate queue using two stacks.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com

>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Anuj Kumar
> Third Year Undergraduate,
> Dept. of Computer Science and Engineering
> NIT Durgapur
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Interview question amazon

2010-12-28 Thread yq Zhang
I think the original question says "Path can go from left subtree tree ,
include root and go to right tree as well". This should mean the path must
include the root.

On Tue, Dec 28, 2010 at 4:52 AM, shanushaan wrote:

> Not clear what path you are referring to.
>
> Question. Should the path include root value always? (What is problem
> with only left or only right path (not containing root))
>   In your example for 16 one more path can be 0 1 5 10 as
> well. Should algo return all the paths or just first one.
>
> On Dec 26, 10:08 pm, MAC  wrote:
> > you are given a bst where each node has a int value , parent pointer ,
> and
> > left and right pointers , write a function to find a path with a given
> sum
> > value. Path can go from left subtree tree , include root and go to right
> > tree as well . we need to find these paths also .
> >
> > 5
> >1 10
> > 0 2  6 11
> >
> > so to find 16 we say it is 1 to 5 to 10
> >
> > --
> > thanks
> > --mac
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Interview question

2010-12-25 Thread yq Zhang
How to solve the second question? it is different from the other question
posted where it requres only SQUARE sub matrix.

Sent from Nexus one
On Dec 25, 2010 11:00 AM, "juver++"  wrote:
> Try to search the answer before sumbitting the question here.
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Find a specific number in a special matrix.

2010-12-25 Thread yq Zhang
But if we sort n*n elements directly using quick sort, the expected sorting
time is only n*n*log(n*n) < n^3.



On Sat, Dec 25, 2010 at 9:19 AM, monty 1987 <1986mo...@gmail.com> wrote:

> Suppose you have a matrix n*m. each column and row of the matrix is
> already sorted. For example:
>
> 1,2,3
> 2,3,4
> 4,5,6
>
> *In how much time we can sort the elements of this matrix  ?
> As far as i m getting idea that if we have n*n elements then we can sort it
> in n^3 time*.
>
> It can be done as---
> 1) The left top element is the smallest one . remove it from the
> matrix.(Store it somewhere)
> 2)Ask from it's right or down element to be present at this new blank
> position (Just like the heap sorting). keep on doing step 2 unless the blank
> reaches the n*m position.
> Again repeat the step 1 and 2 unless thr is no element left in matrix.
>
>
>
>
>
>
> On Sat, Dec 25, 2010 at 9:14 AM, yq Zhang  wrote:
>
>> @mac, Nice solution!
>>
>>
>> On Fri, Dec 24, 2010 at 7:13 PM, MAC  wrote:
>>
>>> move from top rightmost column , go down if the number being searched is
>>> greater or left if the number being seracehd is small .. O(m+n)
>>>
>>> if u wanted to search 5 , u start from 3 (top right) , and since 5>3 , u
>>> go down to 4 , then 5 >4 so go down , u reach 6 . now 5 <6 so u will need to
>>> go left .. till u find 5 or less than 5
>>>
>>> hope this helps
>>>
>>> regards
>>> --mac
>>>
>>>
>>> On Sat, Dec 25, 2010 at 8:25 AM, yq Zhang wrote:
>>>
>>>> Suppose you have a matrix n*m. each column and row of the matrix is
>>>> already sorted. For example:
>>>>
>>>> 1,2,3
>>>> 2,3,4
>>>> 4,5,6
>>>>
>>>> All 3 rows and 3 columns of above matrix are sorted. How to find a
>>>> specific number in the matrix?
>>>> The trivial O(nlogm) solution is to use binary search for all rows. I
>>>> am looking for better solution.
>>>>
>>>> Thanks
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algoge...@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>>
>>>
>>>
>>> --
>>> thanks
>>> --mac
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Find a specific number in a special matrix.

2010-12-24 Thread yq Zhang
@mac, Nice solution!

On Fri, Dec 24, 2010 at 7:13 PM, MAC  wrote:

> move from top rightmost column , go down if the number being searched is
> greater or left if the number being seracehd is small .. O(m+n)
>
> if u wanted to search 5 , u start from 3 (top right) , and since 5>3 , u go
> down to 4 , then 5 >4 so go down , u reach 6 . now 5 <6 so u will need to go
> left .. till u find 5 or less than 5
>
> hope this helps
>
> regards
> --mac
>
>
> On Sat, Dec 25, 2010 at 8:25 AM, yq Zhang  wrote:
>
>> Suppose you have a matrix n*m. each column and row of the matrix is
>> already sorted. For example:
>>
>> 1,2,3
>> 2,3,4
>> 4,5,6
>>
>> All 3 rows and 3 columns of above matrix are sorted. How to find a
>> specific number in the matrix?
>> The trivial O(nlogm) solution is to use binary search for all rows. I
>> am looking for better solution.
>>
>> Thanks
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> thanks
> --mac
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Find a specific number in a special matrix.

2010-12-24 Thread yq Zhang
Suppose you have a matrix n*m. each column and row of the matrix is
already sorted. For example:

1,2,3
2,3,4
4,5,6

All 3 rows and 3 columns of above matrix are sorted. How to find a
specific number in the matrix?
The trivial O(nlogm) solution is to use binary search for all rows. I
am looking for better solution.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: difference x

2010-12-22 Thread yq Zhang
@bhupendra
Nice solution!

Yq

On Wed, Dec 22, 2010 at 11:29 AM, bhupendra dubey
wrote:

> @juver:thanx  for making me work... please notice this
> this also uses the sorted property of the array
>
>  i=0,j=1;
> while((i!=n-1) or  j!=n)
> {
> /*compare difference of a[j] and a[i]*/
> if( (a[j]-[a[i]])>x )
> i++;
> else if( (a[j]-a[i]) j++;
> else
> {
> /*SOLUTION*/
> return;
> }
> }
>
> regards
>
> complexity:O(n)
>
> On Thu, Dec 23, 2010 at 12:29 AM, juver++  wrote:
>
>> Your solution needs extra space and it has only *expected* O(n) time.
>> There is O(n) inplace solution
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> bhupendra dubey
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] complete tree

2010-12-21 Thread yq Zhang
since you know the size, you know exactly the path to the new node.

Sent from Nexus one
On Dec 21, 2010 11:10 PM, "mo...@ismu"  wrote:
>
> it takes O(n) and also O(n)extra space(queue)
>
>
> On Wed, Dec 22, 2010 at 12:37 PM, Saurabh Koar 
wrote:
>>
>> Find the first node whose left child is NULL or Right child is NULL
>> using BFS.(As the tree is complete,all nodes before this will have two
>> children).Insert at that node.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
>> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Minimum Triplet Distance

2010-12-20 Thread yq Zhang
@dave&saura, i dont understand what did you mean.

Sent from Nexus one
On Dec 20, 2010 6:13 AM, "Saurabh Koar"  wrote:
> @Dave : Ya I understand.Thank u.
> @yq: Sorry!! :(
>
> --
> You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
.
> For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Minimum Triplet Distance

2010-12-19 Thread yq Zhang
ok. Suppose you have 3 pointers i, j, k point to the element in A, B, C
respectively. Initialize i = j =k = 0.
for each step, you will compare A[i], B[j], C[k].
if A[i] is the smallest, i++
if B[j] is the smallest, j++
if C[k] is the smallest, k++
(this assumes numbers in A,B,C are unique, you should be able to eliminate
this restriction by changing above logic a little bit.)

for each step compute the current triple distance and keep the minimum.

Thanks



On Sun, Dec 19, 2010 at 9:51 PM, Saurabh Koar wrote:

> @yq: Heyy yq..I m not interested in what is equivalent to what and
> what is not not equivalent to what..I m interested to a specific
> optimized algorithm for the specific problem stated above.If u can
> figure out equivalence u can also devise the algorithm for the above
> problem.Nw would u please state that??or provide any link??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Minimum Triplet Distance

2010-12-19 Thread yq Zhang
This question is equivalent to finding the minimum window contains 3 words
in a document given the position of appearance of each word in the document
by array A, B, C. This could be solved by a typical sliding window algorithm
which is O(n).

Thanks





On Sun, Dec 19, 2010 at 9:06 PM, Saurabh Koar wrote:

> @yq: Plz explain your algorithm.
>
> On 12/20/10, yq Zhang  wrote:
> > Are A, B, C sorted? If so, I believe there is a O(n1+n2+n3) solution for
> > this question.
> >
> > Thanks
> >
> >
> > On Sun, Dec 19, 2010 at 9:57 AM, Saurabh Koar
> > wrote:
> >
> >> You are given 3 integer arrays A, B and C of length n1, n2 and n3
> >> respectively. All arrays are sorted. We define triplet of these 3
> >> arrays as (x,y,z) where x is any integer from A, y from B and z from
> >> C. We define distance of triplet as maximum difference among triplet
> >> elements, i.e. Maximum of x – y, y – z or z – x. Write a program to
> >> find minimum triplet distance. (means there are n1*n2*n3 number of
> >> possible triplets are possible...among all triplets which triplet has
> >> minimum distance...Give only distance, but not triplet elements). Your
> >> program must be as much efficient as possible.
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Algorithm Geeks" group.
> >> To post to this group, send email to algoge...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com
> 
> >
> >> .
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com
> .
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Minimum Triplet Distance

2010-12-19 Thread yq Zhang
Are A, B, C sorted? If so, I believe there is a O(n1+n2+n3) solution for
this question.

Thanks


On Sun, Dec 19, 2010 at 9:57 AM, Saurabh Koar wrote:

> You are given 3 integer arrays A, B and C of length n1, n2 and n3
> respectively. All arrays are sorted. We define triplet of these 3
> arrays as (x,y,z) where x is any integer from A, y from B and z from
> C. We define distance of triplet as maximum difference among triplet
> elements, i.e. Maximum of x – y, y – z or z – x. Write a program to
> find minimum triplet distance. (means there are n1*n2*n3 number of
> possible triplets are possible...among all triplets which triplet has
> minimum distance...Give only distance, but not triplet elements). Your
> program must be as much efficient as possible.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Learning new algorithms

2010-12-14 Thread yq Zhang
Learning new algorithms

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Learning new algorithms

2010-12-14 Thread yq Zhang
Learning new algorithms

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.