Re: [algogeeks] Re: google question

2012-02-29 Thread atul anand
@Dave : is it a working code?? i have executed your code but getting wrong output...and value of s is becoming -ve inside loops. -- 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.

Re: [algogeeks] Re: google question

2012-02-28 Thread Ashish Goel
0.5 ( G(h - 1, i - 1) + G(h - 1, i) ) should be 0.5 ( G(h - 1, i - 1) + G(h - 1, i+1) ) i am not clear why the parents of a cup in upper row are consecutive? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Tue, Feb 28, 2012 at 10:43 AM, Gene

Re: [algogeeks] Re: google question

2012-02-27 Thread Ashish Goel
Dave, why the assumption that nothing is coming from left side. Every cup gets something from cup left above and right above itself when they have something extra? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Mon, Feb 27, 2012 at 8:17 PM, Dave

Re: [algogeeks] Re: google question

2012-02-27 Thread Ashish Goel
Gene, your DP is what i was thinking of but in code i could not coreleate G(h - 1, i - 1) + G(h - 1, i) part (: Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Tue, Feb 28, 2012 at 7:50 AM, Gene gene.ress...@gmail.com wrote: G(h - 1, i - 1) +

Re: [algogeeks] Re: google question

2012-02-27 Thread atul anand
@Dave : my code is not that complicated ...if you ignore the helper function and check fillCup(); it just similar to preorder travesal and pour half to left and right child. here is the explanation :- node* fillCup(node *root,float pour,float capacity) { float temp; if(root==NULL)

Re: [algogeeks] Re: google question

2012-02-27 Thread atul anand
@Dave : yeah sorry its O(n) where n is number of nodes. yeah as i said before its a nice approach... On Tue, Feb 28, 2012 at 10:15 AM, Dave dave_and_da...@juno.com wrote: @Atul: I don't have an n in my algorithm, so I'm not sure what your assessment that my algorithm is O(n^2) means. My

Re: [algogeeks] Re: google question

2012-02-27 Thread atul anand
@Gene , @dave : +1 +1 On Tue, Feb 28, 2012 at 10:49 AM, atul anand atul.87fri...@gmail.comwrote: @Dave : yeah sorry its O(n) where n is number of nodes. yeah as i said before its a nice approach... On Tue, Feb 28, 2012 at 10:15 AM, Dave dave_and_da...@juno.com wrote: @Atul: I don't have

Re: [algogeeks] Re: google question

2012-02-26 Thread Ravi Ranjan
@all same doubt qstn appears to be of binary tree DS but the diagram given in between qstn is not like Binary tree so sharing is there so how sharing is done plz explain?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Re: google question

2012-02-26 Thread atul anand
@Ravi: checkout this code...i have created tree where there is sharing of nodes.. here is my code :- please let me know is case you find any bug. #includestdio.h typedef struct tree{ int idx; float data; struct tree *left; struct tree *right; }node; node *createNode(int index) { node *temp;

Re: [algogeeks] Re: Google Question--Suggest Algo

2011-11-28 Thread Nitin Garg
@Sourabh - whats the running time? On Mon, Nov 28, 2011 at 3:28 AM, Ankur Garg ankurga...@gmail.com wrote: Cool Solution...I was thinking of DP but wasnt clear on the recurrence... Nice thinking man and thanks :) On Mon, Nov 28, 2011 at 2:47 AM, sourabh sourabhd2...@gmail.com wrote:

Re: [algogeeks] Re: Google Question--Suggest Algo

2011-11-27 Thread Ankur Garg
Hey Sourabh Could you please explain the solution in a bit detail perhaps using an example or so..It wud be really helpful ..Just logic not code On Mon, Nov 28, 2011 at 1:03 AM, sourabh sourabhd2...@gmail.com wrote: Looks like a dynamic programming problem Say F(n,k) denotes the maximum

Re: [algogeeks] Re: Google Question--Suggest Algo

2011-11-27 Thread Ankur Garg
Cool Solution...I was thinking of DP but wasnt clear on the recurrence... Nice thinking man and thanks :) On Mon, Nov 28, 2011 at 2:47 AM, sourabh sourabhd2...@gmail.com wrote: Consider the example that you have given: [0,0,1,1,0,0,1,1,0,1,1,0] , here n = 12 and k=3 Now we need to

Re: [algogeeks] Re: GOOGLE QUESTION

2011-07-08 Thread divya raghavan
since its a phone number storing problem, you can sort the numbers and store the differences. That way you can generate the required number on the go On Thu, Jun 30, 2011 at 4:39 AM, juver++ avpostni...@gmail.com wrote: @Navneet Please read problem again - it is about memory efficient storing.

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread sagar pareek
In TRIE , we can store nodes by characters. So it is very easy to search by names and hence their corresponding numbers :) . TRIE saves a lot memory coz it stares a character only once. LIKE :- if i want to save sagar with phone no. 123456789 then we store it in TRIE as : s-NULL | a-NULL |

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread sagar pareek
Sorry for the previous post it got a mistake here take a look again :- In TRIE , we can store nodes by characters. So it is very easy to search by names and hence their corresponding numbers :) . TRIE saves a lot memory coz it stares a character only once. LIKE :- if i want to save sagar

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread Navneet Gupta
I wonder why people have discarded the idea of Hash map here. Searching is obviously the most important task here and if we are to assume that names can be uniformly hashed over a table of 1000 rows with each row containing 1000 names each. Further optimization can be achieved by having names

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread juver++
@samby You are wrong anyway. Main problem is to reduce memory while storing phone numbers. We have 1 million of phones, they have many common prefixes which can be addressed by trie. For storing names, you may use any data structure which is best for the particular problem. Key is name, and

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread juver++
@Navneet Please read problem again - it is about memory efficient storing. -- 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/-/-hsmsOgm2YUJ. To post to this

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread Swathi
Please explain why you think TRIE use more space? To my knowledge TRIE says lot of memory as the common numbers are saved only once.. If you have any good reason then please explain and don't make any single line statements. On Wed, Jun 29, 2011 at 9:21 PM, MONSIEUR monsieur@gmail.com wrote:

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-29 Thread ankit sambyal
@Swathi :We can't use trie data structure to store the phone numbers. The most sound reason is that the users require phone numbers to be sorted by name, but by using the trie data structure we can't get the phone numbers which are sorted by name. Again we can't use trie whose nodes are numbers,

Re: [algogeeks] Re: Google Question

2011-06-24 Thread Anand
http://anandtechblog.blogspot.com/2011/06/bitonic-merge.html On Fri, Jun 24, 2011 at 2:17 AM, sankalp srivastava richi.sankalp1...@gmail.com wrote: 1,2,43,41,5 , 6 Start at a[3] and a[5] Swap them up . Reversing it , we get 1,2,43,5,6,41 This does not work . On Jun 23, 9:05 pm, Swathi

Re: [algogeeks] Re: Google Question

2011-06-24 Thread ankit sambyal
@Anand : Plz explain ur algo ??? On Fri, Jun 24, 2011 at 10:55 AM, Anand anandut2...@gmail.com wrote: http://anandtechblog.blogspot.com/2011/06/bitonic-merge.html On Fri, Jun 24, 2011 at 2:17 AM, sankalp srivastava richi.sankalp1...@gmail.com wrote: 1,2,43,41,5 , 6 Start at a[3] and

Re: [algogeeks] Re: Google Question

2011-06-23 Thread Swathi
We just need to find the start and end of the decreasing sequence then we have to reverse the elements in that decreasing sequence by swapping the elements at both the edges... On Thu, Jun 23, 2011 at 2:13 PM, sankalp srivastava richi.sankalp1...@gmail.com wrote: @piyush Sinha How can you do

Re: [algogeeks] Re: Google Question

2011-06-05 Thread rahul rai
I heard somewhere in some online video lecture that sites like tinyurl change the address using more than base three {base 6 } and then apply hash On 6/4/11, bittu shashank7andr...@gmail.com wrote: well i can speak much on these question.as these algorithms are part of web crawler ..but do u

Re: [algogeeks] Re: Google Question

2011-01-28 Thread Nikhil Jindal
Nishant's soln is incorrect because he assumes, ctrlA and ctrlC are pressed each time ctrlV is pressed. As saikat has pointed out, this is incorrect. According to me: *buff = 0; //keeps track of last ctrlC* *for each i* *{* * dp(i)=max(dp(i-1)+1, 2*dp(i-3), dp(i-1) + buff)* *

Re: [algogeeks] Re: Google Question

2011-01-28 Thread Saikat Debnath
@ Nikhil sir : I have coded the same solution, but was waiting for its correctness to be proved... thanx.. :) On Fri, Jan 28, 2011 at 1:01 PM, Nikhil Jindal fundoon...@yahoo.co.inwrote: Nishant's soln is incorrect because he assumes, ctrlA and ctrlC are pressed each time ctrlV is pressed. As

Re: [algogeeks] Re: Google Question

2011-01-21 Thread Algoose chase
hope this works : #includestdio.h #define MAX(A,B) AB?A:B #defineMIN(A,B) AB?A:B int FindMaxA(int n) { int i,k,factor,max = 0,cur,prev; int* arr = new int[n+1]; int p = MIN(n,4); for( int j = 1;j = p;j++) arr[j] = j; for(i=5;i=n;i++) { k = i-4;

Re: [algogeeks] Re: Google Question

2011-01-20 Thread Saikat Debnath
According to me Nishaanth's solution is incorrect, as let for n =10, your output : m=16 but my output : m =20: For first 5 times hit 'A', then ctrl+A, ctrl+C resulting in 7 keystrokes. then 3 times ctrl+V, which result in m = 20. On Thu, Jan 20, 2011 at 9:24 PM, abhijith reddy d

Re: [algogeeks] Re: Google Question

2011-01-20 Thread Anand
but my output : m =20: For first 5 times hit 'A', then ctrl+A, ctrl+C resulting in 7 keystrokes. then 3 times ctrl+V, which result in m = 20. Try this on a notepad. you will only 15A's On Thu, Jan 20, 2011 at 12:46 PM, Saikat Debnath saikat@gmail.comwrote: According to me Nishaanth's

Re: [algogeeks] Re: Google Question

2011-01-20 Thread Preetam Purbia
Hi, I think this method will work: Possible Number of A's = N/2(1+R) where R=N-(N/2+3) assuming 11/2 = 5 Thanks Preetam On Fri, Jan 21, 2011 at 2:29 AM, Anand anandut2...@gmail.com wrote: but my output : m =20: For first 5 times hit 'A', then ctrl+A, ctrl+C resulting in 7 keystrokes. then

Re: [algogeeks] Re: Google Question

2011-01-19 Thread nishaanth
How about the following dynamic programming solution. Let dp[i] be the max no of As with i keystrokes. dp[i]=max(dp[i-1]+1,2*dp[i-3]) dp[N] is the required solution. Correct me if i am wrong. On Wed, Jan 19, 2011 at 9:20 PM, Raj rajmangaltiw...@gmail.com wrote:

Re: [algogeeks] Re: Google Question: Find kth largest of sum of elements in 2 array

2011-01-12 Thread Ashish Goel
this will not work out a[0]b[0] doesn't mean that a[0]+b[i] is ith largest sum try int a[]={10,8,6,4,1}; int b[]={9,6,3,2,1}; Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Wed, Oct 6, 2010 at 11:36 PM, ligerdave david.c...@gmail.com wrote:

Re: [algogeeks] a google question

2010-07-26 Thread manish bhatia
)x(n-3) would leave n-biggest out? What is the criterion to chose the Ist quardrant? manish... From: topojoy biswas topojoy.bis...@gmail.com To: algogeeks@googlegroups.com Sent: Thu, 22 July, 2010 10:10:58 AM Subject: Re: [algogeeks] a google question im sry

Re: [algogeeks] a google question

2010-07-26 Thread topojoy biswas
...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Thu, 22 July, 2010 10:10:58 AM *Subject:* Re: [algogeeks] a google question im sry the L should look like this: 109 8 5 321 7 17 16 8 18 17 9 19 18 10 20 19 11 21 2019 16

Re: [algogeeks] a google question

2010-07-22 Thread topojoy biswas
consider these arrays: 10 9 8 5 3 2 1 and 13 12 11 10 9 8 7 form a grid like this: 109 8 5 321 7 17 1615 1210 98 8 18 1716 1311 10 9 9 19 1817 1412 12 10 10 20 1918 1513 12 11 11 21 20

Re: [algogeeks] a google question

2010-07-22 Thread topojoy biswas
im sry the L should look like this: 109 8 5 321 7 17 16 8 18 17 9 19 18 10 20 19 11 21 2019 1614 13 12 12 22 2120 1715 14 13 13 23 2221 1816 15 14 I missed a row in the last mail. On Thu, Jul

Re: [algogeeks] a google question

2010-07-21 Thread ankur aggarwal
this ques was asked by google.. it could find any gud soln than order n*n On Mon, Jul 19, 2010 at 10:55 AM, 王奇凡 wqfhena...@gmail.com wrote: @Kushwaha Your programe is wrong. Try this input: a[ ] = {30,25,19,16,14}; b[ ] = {20,18,12,10,8}; the right answer should be 50 48 45 43 42 but

Re: [algogeeks] a google question

2010-07-21 Thread ankur aggarwal
this ques was asked by google.. i* could find any gud soln than order n*n -- 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

Re: [algogeeks] a google question

2010-07-19 Thread Azadeh Mousavi
i think ,you can use the idea of merg (merg sort) --- On Mon, 7/19/10, manish bhatia mb_mani...@yahoo.com wrote: From: manish bhatia mb_mani...@yahoo.com Subject: Re: [algogeeks] a google question To: algogeeks@googlegroups.com Date: Monday, July 19, 2010, 5:03 PM Given two sorted postive

Re: [algogeeks] a google question

2010-07-18 Thread Ashish Goel
: [algogeeks] a google question Here is a solution of O(n) , taking 4 pointers 2 for each array #include cstdio #includeiostream using namespace std; #define N 10 int main(void) { int arr1[N] = {8,7,4,3,2,1,1,1,1,1}; int arr2[N] = {34,23,21,19,15,13,11,8,4,2}; int *p11,*p12

Re: [algogeeks] a google question

2010-07-18 Thread 王奇凡
@Kushwaha Your programe is wrong. Try this input: a[ ] = {30,25,19,16,14}; b[ ] = {20,18,12,10,8}; the right answer should be 50 48 45 43 42 but the program output is 50 48 45 43 37。 2010/5/2 Jitendra Kushwaha jitendra.th...@gmail.com Here is a solution of O(n) , taking 4 pointers 2 for

Re: [algogeeks] a google question

2010-07-16 Thread manish bhatia
...@gmail.com To: algogeeks@googlegroups.com Sent: Sun, 2 May, 2010 9:13:14 PM Subject: Re: [algogeeks] a google question Here is a solution of O(n) , taking 4 pointers 2 for each array #include cstdio #includeiostream using namespace std; #define N 10 int main(void) { int arr1[N

Re: [algogeeks] a google question

2010-05-09 Thread Arun prasath
The nature of the problem involves inserting some elements in heap and retriving back ..It could be solved in worst case O(n * lg(n)). Average case O(n) solution is not there I believe. -Arun prasath N On Fri, Apr 30, 2010 at 5:35 PM, divya sweetdivya@gmail.com wrote: Given two sorted

Re: [algogeeks] a google question

2010-05-02 Thread mohit ranjan
@Algoose Chase point taken Thanks Mohit Ranjan Samsung India Software Operations. On Sat, May 1, 2010 at 8:43 PM, Algoose Chase harishp...@gmail.com wrote: @mohit The idea of DP is fine. When you find the Max i dont think you need to include A[i+1]+B[j+1] because it can never be greater

Re: [algogeeks] a google question

2010-05-02 Thread vignesh radhakrishnan
@divya You're rite. Post a solution if you have one. -- Regards, Vignesh On 2 May 2010 13:14, divya jain sweetdivya@gmail.com wrote: @Mohit according to ur algo if a[1], b[0] has sum greater than a[0],b[1] then i is incremented i is now 2 so for next iteration u ll compare a[2] b[0]

Re: [algogeeks] a google question

2010-05-02 Thread Shishir Mittal
This problem has been discussed before @ http://groups.google.co.in/group/algogeeks/browse_thread/thread/9c1e1aa8cf1ed437/d451cd9468d985f7 I believe, the problem can't be solved in O(n) but only in O(nlog n). @Divya: Are you sure the interviewer explicitly asked for an O(n) time algorithm? On

Re: [algogeeks] a google question

2010-05-02 Thread Algoose Chase
Hi will this work ? since we need Set S with n pairs of largest values , any such pair within the set would (always) contain A[0] or B[0] because they maximize the value of the pair. so // code snippet typedef std::vectorint,int Pairs; Pairs.push(A[0],B[0]) int i = 1; // index for ListA int j

Re: [algogeeks] a google question

2010-05-02 Thread divya jain
i found this question on some site and it was mentioned there todo in o(n). i dont have the solution @ above ur solution doesnt include the case of ncluding a[i] b[j] it takes only a[i] b[0] or b[j] a[0] On 2 May 2010 18:11, Algoose Chase harishp...@gmail.com wrote: Hi will this work ?

Re: [algogeeks] a google question

2010-05-02 Thread Algoose Chase
OOPs.. sorry this doesnt work ! On Sun, May 2, 2010 at 6:11 PM, Algoose Chase harishp...@gmail.com wrote: Hi will this work ? since we need Set S with n pairs of largest values , any such pair within the set would (always) contain A[0] or B[0] because they maximize the value of the pair.

Re: [algogeeks] a google question

2010-05-02 Thread Jitendra Kushwaha
Here is a solution of O(n) , taking 4 pointers 2 for each array #include cstdio #includeiostream using namespace std; #define N 10 int main(void) { int arr1[N] = {8,7,4,3,2,1,1,1,1,1}; int arr2[N] = {34,23,21,19,15,13,11,8,4,2}; int *p11,*p12,*p21,*p22; p11 = p12 = arr1;

Re: [algogeeks] a google question

2010-05-01 Thread Algoose Chase
@mohit The idea of DP is fine. When you find the Max i dont think you need to include A[i+1]+B[j+1] because it can never be greater than both A[i+1]+B[j] and A[i]+B[j+1] since both the lists are sorted in decreasing order. On Fri, Apr 30, 2010 at 8:47 PM, mohit ranjan

Re: [algogeeks] a google question

2010-04-30 Thread Amir hossein Shahriari
On Fri, Apr 30, 2010 at 4:35 PM, divya sweetdivya@gmail.com wrote: Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's say they are decreasingly sorted), we define a set S = {(a,b) | a \in A and b \in B}. Obviously there are n^2 elements in S. The value of such a pair

Re: [algogeeks] a google question

2010-04-30 Thread Kishen Das
Basically the index of ( a + b) in the final array will be ceil(( index of a + index of b )/2). Also if there is a clash of indices you just have to compare the values at those indices and adjust them. I have run my concept with below two arrays and it works !!! Arary A: 1 2 3 4 5 6 Array B: 2 3

Re: [algogeeks] a google question

2010-04-30 Thread mohit ranjan
oops Sorry didn't read properly last algo was for array sorted in ascending order for this case, just reverse the process A[n] and B[n] are two array loop=n, i=0, j=0; while(loop0) // for n largest pairs { print A[i]+B[j]; // sum of first index from both array will be max foo =

Re: [algogeeks] a google question

2010-04-30 Thread Rajesh Patidar
ignore the previous mail it wrongly send. On Fri, Apr 30, 2010 at 11:12 PM, Rajesh Patidar patidarc...@gmail.com wrote: let consider the list in two different part one traversing list B with respect to A and A with B (a.len,b.len) is always solution a1=a2=a.len On Fri, Apr 30, 2010 at 5:35

Re: [algogeeks] a google question

2010-04-30 Thread mohit ranjan
Hi Divya, A[n] and B[n] are two array loop=n, i=n-1, j=n-1; while(loop0) // for n largest pairs { print A[i]+B[j]; // sum of last index from both array will be max foo = MAX ( A[i-1]+B[j], A[i-1]+B[j-1], A[i]+B[j-1] ) // using DP moving backward if foo=A[i-1]+B[j]; i--