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

2012-08-11 Thread yq Zhang
nos in character array so only characters will be printed not nos On Sat, Aug 11, 2012 at 2:18 AM, yq Zhang zhangyunq...@gmail.com 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

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,

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 narayan.shiv...@gmail.comwrote: this is similar to conversion of no in base 26.( where digits are a,b,c,d...z) just think it like

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 anks...@gmail.com 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

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

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 bagana.bharatku...@gmail.comwrote: @Dave Your solution works if the total no.of records(ssn numbers) is 1000 million. But

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 monish.gup...@gmail.com wrote: I think it might done using function of following

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

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 jalaj.jaiswa...@gmail.com 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

Re: [algogeeks] Re: Amazon Again

2011-01-29 Thread yq Zhang
can you prove it? On Jan 29, 2011 6:38 PM, Wei.QI qiw...@gmail.com 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

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.

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

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 saivivekh.swaminat...@gmail.com 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

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 souravs...@gmail.com wrote: @Juvier, @yq Zhang In your approach, when you are asked pop_front() you keep popping from one

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

2011-01-05 Thread yq Zhang
in bottom right quadrant if xA[n/2][n/2] search in other 3 quadrants On Sat, Dec 25, 2010 at 8:25 AM, yq Zhang zhangyunq...@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 All 3 rows and 3 columns of above

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++ avpostni...@gmail.com 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

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

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 anuj.bhambh...@gmail.com wrote: @juver++ how will implwment find_min() function? On Sun, Jan 2, 2011 at 2:33 PM, juver++ avpostni...@gmail.com wrote:

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 er.srivastavaro...@gmail.comwrote: Not clear what path you are referring to.

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

2010-12-25 Thread yq Zhang
) 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

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++ avpostni...@gmail.com wrote: Try to search the answer before sumbitting the question here. -- You received this

[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

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

2010-12-24 Thread yq Zhang
, 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 zhangyunq...@gmail.com wrote: Suppose you have a matrix n*m. each column and row of the matrix

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 bhupendra@gmail.comwrote: @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]*/

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 mohan...@gmail.com wrote: it takes O(n) and also O(n)extra space(queue) On Wed, Dec 22, 2010 at 12:37 PM, Saurabh Koar saurabhkoar...@gmail.com wrote: Find the first

Re: [algogeeks] Re: Minimum Triplet Distance

2010-12-20 Thread yq Zhang
@davesaura, i dont understand what did you mean. Sent from Nexus one On Dec 20, 2010 6:13 AM, Saurabh Koar saurabhkoar...@gmail.com 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

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 saurabhkoar...@gmail.comwrote: You are given 3 integer arrays A, B and C of length n1, n2 and n3 respectively. All arrays are sorted. We define triplet

Re: [algogeeks] Minimum Triplet Distance

2010-12-19 Thread yq Zhang
Koar saurabhkoar...@gmail.comwrote: @yq: Plz explain your algorithm. On 12/20/10, yq Zhang zhangyunq...@gmail.com 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 saurabhkoar

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

[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,

[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,