Re: [algogeeks] Google Q : all anagrams next to each other

2012-05-23 Thread partha sarathi Mohanty
@ashish : couldnt get u.. can u give an example??

On Tue, May 22, 2012 at 5:45 PM, Prem Krishna Chettri hprem...@gmail.comwrote:

 What I Could possibly think of is

  For each string S1 that is an anagram of some string S, use Map and Store
 the Key Value as (S1,S). Now there is a trick here abt how to reduce Time
 Complexity here...

  Now its easy to put all string which has correspondence S next to each
 other. This is Simple one.

 Inplace.. Hv to think abt .. I doubt, as we need some space to get the
 anagrams Dude..

 Prem

 On Tue, May 22, 2012 at 5:18 PM, Ashish Goel ashg...@gmail.com wrote:

 Write a method to sort an array of strings so that all the anagrams are
 next to each other.

 What i could think of is preparing a multi linked list( multimap) whereby
 the key for each string is the sorted representation of the string(eg if
 string is gac, its sorted representation is acg). Walk of all lists of this
 multimap to give all anagrams.

 Is there any other better solution for this problem?
 Can this be done *inplace*?

 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 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.



[algogeeks] Google Q : all anagrams next to each other

2012-05-22 Thread Ashish Goel
Write a method to sort an array of strings so that all the anagrams are
next to each other.

What i could think of is preparing a multi linked list( multimap) whereby
the key for each string is the sorted representation of the string(eg if
string is gac, its sorted representation is acg). Walk of all lists of this
multimap to give all anagrams.

Is there any other better solution for this problem?
Can this be done *inplace*?

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 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] Google Q : all anagrams next to each other

2012-05-22 Thread Prem Krishna Chettri
What I Could possibly think of is

 For each string S1 that is an anagram of some string S, use Map and Store
the Key Value as (S1,S). Now there is a trick here abt how to reduce Time
Complexity here...

 Now its easy to put all string which has correspondence S next to each
other. This is Simple one.

Inplace.. Hv to think abt .. I doubt, as we need some space to get the
anagrams Dude..

Prem

On Tue, May 22, 2012 at 5:18 PM, Ashish Goel ashg...@gmail.com wrote:

 Write a method to sort an array of strings so that all the anagrams are
 next to each other.

 What i could think of is preparing a multi linked list( multimap) whereby
 the key for each string is the sorted representation of the string(eg if
 string is gac, its sorted representation is acg). Walk of all lists of this
 multimap to give all anagrams.

 Is there any other better solution for this problem?
 Can this be done *inplace*?

 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 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.



[algogeeks] Google Q: longest word made of subwords within the list

2012-05-22 Thread Ashish Goel
write a program to find the longest word made of other words. For instance,
If my file has the following words (sorted):
test
tester
testertest
testing
testingtester

The longest word should be testingtester. Trie is the solution, what is the
best Order possible?
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 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] Google Q: longest word made of subwords within the list

2012-05-22 Thread Prem Krishna Chettri
Yea this is a Straight Cut Trie Question No Doubt.. Perhaps DWAG may be
taken into consideration..

T(O)=O(n) can be done easily.. ( By tracking Second and First Longest word
found soFar and updating otherwise accordingly)

Can someone do it better?


On Tue, May 22, 2012 at 6:15 PM, Ashish Goel ashg...@gmail.com wrote:

 write a program to find the longest word made of other words. For
 instance, If my file has the following words (sorted):
 test
 tester
 testertest
 testing
 testingtester

 The longest word should be testingtester. Trie is the solution, what is
 the best Order possible?
 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 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] Google Q : all anagrams next to each other

2012-05-22 Thread aanchal goyal
Anyways we need to sort all the words atleast once,  one way is
To travel throught the list sorting each word and making  a pair of the
orginal and the sorted word.
For Ex. If one of the original word in list is aanchal sorted is
aaachln. So store the pair aanchal, aaachln
Now sort this list of pairs based on 2nd value.

-- 
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] Google Q: longest word made of subwords within the list

2012-05-22 Thread atul anand
@krishna : tracking just second and first longest word would be enough??

what if input has word which is made by repeating small word again and again
test
tester
testertest
testing
testingtester
testtesttesttesttest  // added word

and by saying O(n) .. n= total number of alphabets in the file rite??

On Tue, May 22, 2012 at 7:17 PM, Prem Krishna Chettri hprem...@gmail.comwrote:

 Yea this is a Straight Cut Trie Question No Doubt.. Perhaps DWAG may be
 taken into consideration..

 T(O)=O(n) can be done easily.. ( By tracking Second and First Longest word
 found soFar and updating otherwise accordingly)

 Can someone do it better?


 On Tue, May 22, 2012 at 6:15 PM, Ashish Goel ashg...@gmail.com wrote:

 write a program to find the longest word made of other words. For
 instance, If my file has the following words (sorted):
 test
 tester
 testertest
 testing
 testingtester

 The longest word should be testingtester. Trie is the solution, what is
 the best Order possible?
 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 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] Google Q: longest word made of subwords within the list

2012-05-22 Thread atul anand
yes ,longest word can be found while inserting each word it the TRIE.

 *By tracking Second and First Longest word found** -- *confused me ...what
you were trying to say.
tracking can be done but become little difficult if input is something like
this :-

best
bestest
test
testbest
testbesttest

btw TRIE containing only distinct word i.e words not made up of sub words
would be enough to solve the problem
On Tue, May 22, 2012 at 11:40 PM, Prem Krishna Chettri
hprem...@gmail.comwrote:

 Haha,, Do I hv to respond Here.. Anyways Guys And Specially Mr.Atul. Here
 is the Long way to Make you understand..

 Yes 2 ptr is Alwayz Enuf now Why??

  Yes Words can be a assembly of words.. Like say you sample
 testtesttest..n time.. So Lets go back to Simple recursion.. Tell me how
 U calculate recursive Factorial (n) ?? similarly to get testtest...n there
 must be one string called testtest...(n-1) and the other test right !!! So
 2 ptr is alwayz enuf to resolve this.

   Now as we all know the smart way to update these valuable pointers are
 keep looking for possible next level words.. So I've put.(*Updating
 Otherwise Accordingly)*

 For your second condescending question.

   It is well known if U remember DWAG/TRIE that they have
 nodes which *MAY *contains Alphabets.. as we move down using branches
 alwayz. so. if U are Considering Node as Alphabets (Narrow way of thinking)
 than yes, but I would like to be more general and so will like to put as
 N=Number of Nodes to be visited.

 BR,
 Prem


 On Tue, May 22, 2012 at 10:41 PM, atul anand atul.87fri...@gmail.comwrote:

 @krishna : tracking just second and first longest word would be enough??

 what if input has word which is made by repeating small word again and
 again
 test
 tester
 testertest
 testing
 testingtester
 testtesttesttesttest  // added word

 and by saying O(n) .. n= total number of alphabets in the file rite??

 On Tue, May 22, 2012 at 7:17 PM, Prem Krishna Chettri hprem...@gmail.com
  wrote:

 Yea this is a Straight Cut Trie Question No Doubt.. Perhaps DWAG may be
 taken into consideration..

 T(O)=O(n) can be done easily.. ( By tracking Second and First Longest
 word found soFar and updating otherwise accordingly)

 Can someone do it better?


 On Tue, May 22, 2012 at 6:15 PM, Ashish Goel ashg...@gmail.com wrote:

 write a program to find the longest word made of other words. For
 instance, If my file has the following words (sorted):
 test
 tester
 testertest
 testing
 testingtester

 The longest word should be testingtester. Trie is the solution, what is
 the best Order possible?
 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 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.


  --
 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] Google Q: longest word made of subwords within the list

2012-05-22 Thread Prem Krishna Chettri
Thank you to understanding Me..

  Well For Trie.. I don't hv to say much more to say except the basic need
which says Collect Common Prefix . If it didnt ring the bell.. than Hv a
look at strings MADAM and MADAMIAMADAM stored in your TRIE .. Just draw a
pictorial representation.



On Wed, May 23, 2012 at 12:20 AM, atul anand atul.87fri...@gmail.comwrote:

 yes ,longest word can be found while inserting each word it the TRIE.

  *By tracking Second and First Longest word found** -- *confused me
 ...what you were trying to say.
 tracking can be done but become little difficult if input is something
 like this :-

 best
 bestest
 test
 testbest
 testbesttest

 btw TRIE containing only distinct word i.e words not made up of sub words
 would be enough to solve the problem

 On Tue, May 22, 2012 at 11:40 PM, Prem Krishna Chettri hprem...@gmail.com
  wrote:

 Haha,, Do I hv to respond Here.. Anyways Guys And Specially Mr.Atul. Here
 is the Long way to Make you understand..

 Yes 2 ptr is Alwayz Enuf now Why??

  Yes Words can be a assembly of words.. Like say you sample
 testtesttest..n time.. So Lets go back to Simple recursion.. Tell me how
 U calculate recursive Factorial (n) ?? similarly to get testtest...n there
 must be one string called testtest...(n-1) and the other test right !!! So
 2 ptr is alwayz enuf to resolve this.

   Now as we all know the smart way to update these valuable pointers are
 keep looking for possible next level words.. So I've put.(*Updating
 Otherwise Accordingly)*

 For your second condescending question.

   It is well known if U remember DWAG/TRIE that they have
 nodes which *MAY *contains Alphabets.. as we move down using branches
 alwayz. so. if U are Considering Node as Alphabets (Narrow way of thinking)
 than yes, but I would like to be more general and so will like to put as
 N=Number of Nodes to be visited.

 BR,
 Prem


 On Tue, May 22, 2012 at 10:41 PM, atul anand atul.87fri...@gmail.comwrote:

 @krishna : tracking just second and first longest word would be enough??

 what if input has word which is made by repeating small word again and
 again
 test
 tester
 testertest
 testing
 testingtester
 testtesttesttesttest  // added word

 and by saying O(n) .. n= total number of alphabets in the file rite??

 On Tue, May 22, 2012 at 7:17 PM, Prem Krishna Chettri 
 hprem...@gmail.com wrote:

 Yea this is a Straight Cut Trie Question No Doubt.. Perhaps DWAG may be
 taken into consideration..

 T(O)=O(n) can be done easily.. ( By tracking Second and First Longest
 word found soFar and updating otherwise accordingly)

 Can someone do it better?


 On Tue, May 22, 2012 at 6:15 PM, Ashish Goel ashg...@gmail.com wrote:

 write a program to find the longest word made of other words. For
 instance, If my file has the following words (sorted):
 test
 tester
 testertest
 testing
 testingtester

 The longest word should be testingtester. Trie is the solution, what
 is the best Order possible?
 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 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.


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

Re: [algogeeks] Google Q: longest word made of subwords within the list

2012-05-22 Thread atul anand
think in term of following input case :-

best
test
testbest

than i guess you will come to knw why i got confused at first place.
*madammadam*
*testtesttest *
ignore this type of test case.

On Wed, May 23, 2012 at 12:40 AM, Prem Krishna Chettri
hprem...@gmail.comwrote:

 Thank you to understanding Me..

   Well For Trie.. I don't hv to say much more to say except the basic need
 which says Collect Common Prefix . If it didnt ring the bell.. than Hv a
 look at strings MADAM and MADAMIAMADAM stored in your TRIE .. Just draw a
 pictorial representation.



 On Wed, May 23, 2012 at 12:20 AM, atul anand atul.87fri...@gmail.comwrote:

 yes ,longest word can be found while inserting each word it the TRIE.

  *By tracking Second and First Longest word found** -- *confused me
 ...what you were trying to say.
 tracking can be done but become little difficult if input is something
 like this :-

 best
 bestest
 test
 testbest
 testbesttest

 btw TRIE containing only distinct word i.e words not made up of sub words
 would be enough to solve the problem

 On Tue, May 22, 2012 at 11:40 PM, Prem Krishna Chettri 
 hprem...@gmail.com wrote:

 Haha,, Do I hv to respond Here.. Anyways Guys And Specially Mr.Atul.
 Here is the Long way to Make you understand..

 Yes 2 ptr is Alwayz Enuf now Why??

  Yes Words can be a assembly of words.. Like say you sample
 testtesttest..n time.. So Lets go back to Simple recursion.. Tell me how
 U calculate recursive Factorial (n) ?? similarly to get testtest...n there
 must be one string called testtest...(n-1) and the other test right !!! So
 2 ptr is alwayz enuf to resolve this.

   Now as we all know the smart way to update these valuable pointers are
 keep looking for possible next level words.. So I've put.(*Updating
 Otherwise Accordingly)*

 For your second condescending question.

   It is well known if U remember DWAG/TRIE that they
 have nodes which *MAY *contains Alphabets.. as we move down using
 branches alwayz. so. if U are Considering Node as Alphabets (Narrow way of
 thinking) than yes, but I would like to be more general and so will like to
 put as N=Number of Nodes to be visited.

 BR,
 Prem


 On Tue, May 22, 2012 at 10:41 PM, atul anand atul.87fri...@gmail.comwrote:

 @krishna : tracking just second and first longest word would be enough??

 what if input has word which is made by repeating small word again and
 again
 test
 tester
 testertest
 testing
 testingtester
 testtesttesttesttest  // added word

 and by saying O(n) .. n= total number of alphabets in the file rite??

 On Tue, May 22, 2012 at 7:17 PM, Prem Krishna Chettri 
 hprem...@gmail.com wrote:

 Yea this is a Straight Cut Trie Question No Doubt.. Perhaps DWAG may
 be taken into consideration..

 T(O)=O(n) can be done easily.. ( By tracking Second and First Longest
 word found soFar and updating otherwise accordingly)

 Can someone do it better?


 On Tue, May 22, 2012 at 6:15 PM, Ashish Goel ashg...@gmail.comwrote:

 write a program to find the longest word made of other words. For
 instance, If my file has the following words (sorted):
 test
 tester
 testertest
 testing
 testingtester

 The longest word should be testingtester. Trie is the solution, what
 is the best Order possible?
 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 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.


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

Re: [algogeeks] GOOGLE Q

2011-07-09 Thread sunny agrawal
i have an O(nlgn) solution in mind using O(n^2) memory

All the values can be thought as the following matrix
(a0+b0) (a0+b1) (a0+b2).(a0+bn-1)
(a1+b0) (a1+b1) (a1+b2).(a1+bn-1)
. .
. .
. .
. .
. .
. .
. .
(an-1+b0) (an-1+b1) (an-1+b2)..(an-1+bn-1)

now as we can see all the rows and columns are sorted.
now i will refer (ai,bj) as (i,j)
make a heap
insert (0,0) in  heap

now do the following n times
extract a pair value (i,j)
and insert (i+1,j) and (i,j+1) in heap not inserted

TC : O(nlgn)
SC: O(n^2) to take care of already present elements in the heap



On Sat, Jul 9, 2011 at 4:54 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 Given two sorted positive integer arrays A(n) and B(n). 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 is defined as Val(a,b) = a + b. Now we want to get the n pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 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.




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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.



[algogeeks] GOOGLE Q

2011-07-08 Thread Piyush Sinha
Given two sorted positive integer arrays A(n) and B(n). 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 is defined as Val(a,b) = a + b. Now we want to get the n pairs
from S with largest values. The tricky part is that we need an O(n)
algorithm.


-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

-- 
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] GOOGLE Q

2011-05-20 Thread Amit Jaspal
Use Product of Primes as Hash function , this would give no collision in
case of anagrams.

On Tue, May 17, 2011 at 9:53 PM, Anand anandut2...@gmail.com wrote:

 For any given word.
 - Find the lexicographic ordering and calculate it hash.
 - Find all permutation of the string
 - Check each permutation if it's a valid word
 -  if so store it at the same hash index.



 On Tue, May 17, 2011 at 7:16 AM, Ashish Goel ashg...@gmail.com wrote:

 hash..

 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652


 On Tue, May 17, 2011 at 11:36 AM, Piyush Sinha 
 ecstasy.piy...@gmail.comwrote:

 Given an English word in the form of a string, how can you quickly
 find all valid
 anagrams for that string (all valid rearrangements of the letters that
 form valid
 English words)?
 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 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.




-- 
Amit Jaspal.

Men do less than they ought,
unless they do all they can

-- 
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] GOOGLE Q

2011-05-20 Thread Ashim Kapoor
How will BFS give a rearrangement ?

-- 
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.



[algogeeks] GOOGLE Q

2011-05-17 Thread Piyush Sinha
Given an English word in the form of a string, how can you quickly
find all valid
anagrams for that string (all valid rearrangements of the letters that
form valid
English words)?
-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

-- 
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] GOOGLE Q

2011-05-17 Thread Manjeet Chayel
Use BFS?

On Tue, May 17, 2011 at 11:36 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 Given an English word in the form of a string, how can you quickly
 find all valid
 anagrams for that string (all valid rearrangements of the letters that
 form valid
 English words)?
 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 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.




-- 
Cheers!!
Manjeet Chayel

-- 
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] GOOGLE Q

2011-05-17 Thread Anand
For any given word.
- Find the lexicographic ordering and calculate it hash.
- Find all permutation of the string
- Check each permutation if it's a valid word
-  if so store it at the same hash index.


On Tue, May 17, 2011 at 7:16 AM, Ashish Goel ashg...@gmail.com wrote:

 hash..

 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652


 On Tue, May 17, 2011 at 11:36 AM, Piyush Sinha 
 ecstasy.piy...@gmail.comwrote:

 Given an English word in the form of a string, how can you quickly
 find all valid
 anagrams for that string (all valid rearrangements of the letters that
 form valid
 English words)?
 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 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] Google Q

2011-05-14 Thread Ashish Goel
not clear, can u elaborate..

Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Fri, May 13, 2011 at 7:15 PM, Bhavesh agrawal agr.bhav...@gmail.comwrote:

 This problem can be solved using 2 heaps and the median can always be
 accessed in O(1) time ,the first node.

 --
 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.



[algogeeks] Google Q

2011-05-13 Thread Ashish Goel
Q. Numbers are randomly generated and stored into an (expanding) array. How
would you keep track of the median?



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 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] Google Q

2011-05-13 Thread Bhavesh agrawal
This problem can be solved using 2 heaps and the median can always be
accessed in O(1) time ,the first node.

-- 
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] Google Q

2011-05-13 Thread Anand
http://anandtechblog.blogspot.com/2010/11/find-next-higher-number-which-has-same.html

On Thu, May 12, 2011 at 10:52 PM, ArPiT BhAtNaGaR 
arpitbhatnagarm...@gmail.com wrote:

 if u knw the no. of 1's in no .
 I mean can afford the complexity of finding no. of 1's of no.


 den if no of 1'
 in say 101011
  is 4   den largest is00
 smalest is   00


 On Fri, May 13, 2011 at 8:38 AM, Ashish Goel ashg...@gmail.com wrote:

 Given an integer, print the next smallest and next largest numbers that
 have the same number of 1’s in their binary representations


 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 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.




 --
 Thanks  Regards

 Arpit Bhatnagar
 (Computer Engineering)
 (MNIT JAIPUR)

  --
 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.



[algogeeks] Google Q

2011-05-12 Thread Ashish Goel
Using bit manipulation, implement add, subtract and multiply on two
integers. You cannot use any arithmetic operations, such as +, - or *.


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 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.



[algogeeks] Google Q

2011-05-12 Thread Ashish Goel
Given an integer, print the next smallest and next largest numbers that have
the same number of 1’s in their binary representations


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 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] Google Q

2011-05-12 Thread ArPiT BhAtNaGaR
if u knw the no. of 1's in no .
I mean can afford the complexity of finding no. of 1's of no.


den if no of 1'
in say 101011
 is 4   den largest is00
smalest is   00

On Fri, May 13, 2011 at 8:38 AM, Ashish Goel ashg...@gmail.com wrote:

 Given an integer, print the next smallest and next largest numbers that
 have the same number of 1’s in their binary representations


 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 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.




-- 
Thanks  Regards

Arpit Bhatnagar
(Computer Engineering)
(MNIT JAIPUR)

-- 
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.