Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread Sairam
So, how do you do that sir? Basically , we should identify all the paths between those two nodes and keep track of maximum of sums. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread kunal rustgi
@ravi yep, you're right. But method is similar to finding diameter as given on geeksforgeeks as atul suggested . Thanks. On Mon, Aug 27, 2012 at 11:23 PM, Ravi Maggon maggonr...@gmail.com wrote: @atul: I think he is asking for max. sum of elements between 2 leaf nodes and not the max

[algogeeks] 5 tyres 10000 Kilometers..

2012-08-28 Thread Prem Krishna Chettri
Guys Something good to share here.. Query :- Tomorrow I am Planning to take my car for a ride of 1 ( Ten Thousands ) Km. As the journey will be rough so I am planning to pack 5 new tyres.. Now being very conservative, I want to use each of them such that they all wear equally.. Now the

[algogeeks] Re: 5 tyres 10000 Kilometers..

2012-08-28 Thread Dave
@Prem: You will travel 40,000 tire (American spelling) km. Therefore, each tire needs to be on the ground for 8,000 km. One way to accomplish this is to rotate the 5 tires each 2,000 km. Then, each tire will be on each wheel for 2,000 km, and will be the spare for 2,000 km. Another way, with

Re: [algogeeks] 5 tyres 10000 Kilometers..

2012-08-28 Thread Aditya Virmani
If there are total 5 tyres, including the 4 attached ones... you can change do a rotation, change tyre after every 2000 kms( or the factors of 2000), in that case, the journey by each one would be 8000. i think there can be several interpretations of the qn. IF for five extra tyres, wud mean equal

Re: [algogeeks] 5 tyres 10000 Kilometers..

2012-08-28 Thread Prem Krishna Chettri
@Dave.. Yeah that correct .. Its fairly simple to get in the interviews. A bit trickier one for me is to get the corrupted link list correction... I have seen but not concentrated enough during the hours.. On Tue, Aug 28, 2012 at 10:02 PM, Aditya Virmani virmanisadi...@gmail.comwrote:

Re: [algogeeks] Suggest algo...

2012-08-28 Thread pankajsingh
Code:- #includeiostream #includevector using namespace std; void recursion(int sum,int i,vectorint v,int size) { vectorint v1=v; int size1=size; if(sum==0) { for(int k=0;ksize;k++) coutv[k] ; coutendl; } else { for(int j=i+1;j10;j++)

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread vaibhav shukla
I guess it might be finding maximum sum path for left subtree + max sum path for right subtree + root-data As in case of finding the diameter which say height(root-left)+height(root-right)+1 Please correct me! On Mon, Aug 27, 2012 at 11:46 PM, kunal rustgi rustogi.ku...@gmail.comwrote: @ravi

Re: [algogeeks] amazon Interview

2012-08-28 Thread pankajsingh
@atul-I think This Should work for n dimension- complexity O(n^no.of dimesions) :- have N-dimension check for which Tile can contain which Tile.i.e (3,3,4) can contain (2,3,4) . Now 1.Take the titles which cannot contain any-other tile set no-of tile if it is base =1; 2.now take tiles which can

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread pankajsingh
Hope This will Work.. int Recursion(node *root) { if(root-left==Nullroot-right==Null) { return root-data; } int a=0,b=0; a=recursion(root-left); b=recursion(root-right); if(a+b+root-datamax) max=a+b+root-data; return max(a,b)+root-data; } -- You received this message because you are subscribed

Re: [algogeeks] Re: Printing random word from file

2012-08-28 Thread pankajsingh
@all-This is almost the same question asked in facebook.. Dave sir is correct! Example-file contain only a b a c; Then step1: save a; step2: save b with probability of value 0 by rand()%2; therefore pr[1]=1/2;pr[2]=1/2; step3; save a with probability of value 0 by rand()%3; therefore

[algogeeks] Fwd: Snapdeal placement proceedure

2012-08-28 Thread sachin singh
-- Forwarded message -- From: sachin singh sachin...@gmail.com Date: Tue, Aug 28, 2012 at 10:23 PM Subject: Snapdeal placement proceedure To: algogeeks@googlegroups.com Can anyone tell about the recruitment process of snapdeal? I mean how to prepare for the written test?What

[algogeeks] Search an element in a sorted and pivoted array

2012-08-28 Thread rahul sharma
plz provide me algo for this,thnx -- 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

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread pankajsingh
@vaibhav-yup :-) -- 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

[algogeeks] Re: max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread Navin Gupta
I think the path between two leaves always passes thru root. Now we can keep track of root-to-leaf path whose sum is max and secondMax among all sums. Now between this two leaves path, root is repeated. Hence actual sum is maxsum + secondMaxSum - root-val; This can be done by iterative inorder

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread kunal rustgi
int maxLtoLSum(NODE *root,int *sum) { int ls=0,rs=0,lsum=0,rsum=0; if(root==NULL) { *sum=0; return 0; } lsum= maxLtoLSum (root-left,ls); rsum= maxLtoLSum (root-right,rs); *sum=max(ls,rs) + root-data; return max(ls + rs + root-data, max(lsum,rsum)); } On Tue, Aug 28,

Re: [algogeeks] Re: Printing random word from file

2012-08-28 Thread Dave
@Kailash: I assumed a function random() which generates uniformly distributed double precision random numbers between 0 and 1. Usually such a generator would produce numbers with 53 bit precision, so I guess that is between 15 and 16 digits after the decimal point. Just google random number

Re: [algogeeks] Re: Printing random word from file

2012-08-28 Thread Dave
@Pankaj: My only complaint is that rand()%n is not uniformly distributed between 0 and n-1. To see this, suppose rand() produces positive 32-bit integers, so they have the range 0 to 2^31 - 1 = 2,147,483,647. Now, suppose there are 100,000 words in the file. When you are computing

[algogeeks] Re: Search an element in a sorted and pivoted array

2012-08-28 Thread Dave
@Rahul: Please tell us what you mean by a pivoted array. Dave On Tuesday, August 28, 2012 12:56:03 PM UTC-5, rahul sharma wrote: plz provide me algo for this,thnx -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on

Re: [algogeeks] Re: Printing random word from file

2012-08-28 Thread pankajsingh
@Dave Sir-Got ur point..thnks!! -- 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

Re: [algogeeks] Re: Algorithm page

2012-08-28 Thread Wladimir Tavares
http://marathoncode.blogspot.com.br/2012/08/ano-turing.html http://marathoncode.blogspot.com.br/2012/08/logaritmo-discreto.html http://marathoncode.blogspot.com.br/2012/08/registrador-de-deslocamento.html http://marathoncode.blogspot.com.br/2012/08/paradoxo-do-aniversario.html