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

[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

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

[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

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

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

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

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

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

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

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

[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

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

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

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

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*

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

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

[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

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

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

[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

[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

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,