Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2012-01-19 Thread Arun Vishwanathan
@varun : isn't the longest common subsequence abccba and longest common substring is abc or cba?in any case what is the longest palindrom in the given string abcdecba?? isnt it the individual letters itself ie length max is 1? On Wed, Jun 22, 2011 at 10:45 AM, varun gupta varun.gt...@gmail.com

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-07-01 Thread Dumanshu
@hary: nhin, its some constant multiple of n. O(constant*n) for a string of length n, 2*n-1 positions are there. every time i calculate the next center using prev center value if the value at prev center is a large one then this next center value skips that many positions to compensate.. if the

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-07-01 Thread bittu
i have posted some time back but that is O(N) , need to code suffix tree will do that asap i get the time. Thanks Shashank CSE BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-07-01 Thread bittu
sorry for typo that is O(N^2) Thanks Shashank -- 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] Re: Amazon - Longest palindrome in a string in O(n)

2011-07-01 Thread SVIX
I don't think a O(n) solution exists... for each candidate string we find, we'll still have to validate that its a palindrome right? On Jul 1, 5:10 am, bittu shashank7andr...@gmail.com wrote: sorry for typo that is O(N^2) Thanks Shashank -- You received this message because you are

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-07-01 Thread Arpit Sood
btw, they don't need a substring, but a subsequence. On Thu, Jun 30, 2011 at 11:41 PM, Dumanshu duman...@gmail.com wrote: heres the code: http://ideone.com/aiG1m using the algo from http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/ On Jun 21,

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-30 Thread Dumanshu
heres the code: http://ideone.com/aiG1m using the algo from http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/ On Jun 21, 11:31 pm, Swathi chukka.swa...@gmail.com wrote: Does any one know how to return the Longest palindrome in a string in O(n). From

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-29 Thread Wladimir Tavares
I know that is not the best solution but here we go: p [i] [j] = 1 if s [i.. j] is palindrome, 0 otherwise p [i] [i] = 1 p [i] [i +1] = s [i] == s [i +1] p [i] [k] = s [i] == s [k] p [i +1] [k-1], k i +1 time complexity = O (n ^ 2) Space complexity = O (n ^ 2) You can modify the algorithm to

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-23 Thread Avinash
http://stevekrenzel.com/articles/longest-palnidrome But for some reason it is failing for string ISAAS, may be my understanding is incorrect. Thanks Avinash http://avi-programming-blog.blogspot.com/ On Jun 21, 11:31 pm, Swathi chukka.swa...@gmail.com wrote: Does any one know how to return the

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-23 Thread Anand
http://anandtechblog.blogspot.com/2010/06/find-longest-palindromic-substring-in.html On Wed, Jun 22, 2011 at 9:28 PM, Avinash dongre.avin...@gmail.com wrote: http://stevekrenzel.com/articles/longest-palnidrome But for some reason it is failing for string ISAAS, may be my understanding is

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread SVIX
couldn't we just collect all the letters that occur more than twice and play them back even number of times symmetrically? and if there are more letters left, we can put one of them in the center... linear time need additional memory for some kind of hashing On Jun 21, 11:31 am, Swathi

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sanjay ahuja
Suffix tree can solve longest common substring problem in o(n) and longest palindrome in string S is nothing but longest common substring between string s and its reverse. On Wed, Jun 22, 2011 at 9:31 PM, ankit mehta mehta.bond...@gmail.com wrote: You dont have to create longest palindrome,

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread ankit mehta
Consider string: abcdecba Reverse of above string: abcedcba Longest common substring: abc and cba : Both not Palindromes! On Jun 22, 9:29 pm, sanjay ahuja sanjayahuja.i...@gmail.com wrote: Suffix tree can solve longest common substring problem in o(n) and longest palindrome in string S is

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
LCS is abcdcba or abcecba not abc or cba On Wed, Jun 22, 2011 at 10:15 PM, ankit mehta mehta.bond...@gmail.comwrote: Consider string: abcdecba Reverse of above string: abcedcba Longest common substring: abc and cba : Both not Palindromes! On Jun 22, 9:29 pm, sanjay ahuja

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread varun gupta
Does the question mean non-continuous substring? I think it should be continuous substring which is palindrome with in the given string. LCS wouldn't solve problem in this case. On Wed, Jun 22, 2011 at 10:29 PM, sunny agrawal sunny816.i...@gmail.comwrote: LCS is abcdcba or abcecba not abc or

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
LCS stands for Longest Common Substring -- 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

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread varun gupta
That is what ankit said. Consider string: abcdecba Reverse of above string: abcedcba Longest common substring: abc and cba : you are calculating longest common *subsequence* not substring. Substring in continuous. On Wed, Jun 22, 2011 at 10:48 PM, sunny agrawal sunny816.i...@gmail.comwrote:

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread SVIX
ah... i misunderstood the question... sorry.. On Jun 22, 12:01 pm, ankit mehta mehta.bond...@gmail.com wrote: You dont have to create longest palindrome, you have to find the longest palindrome. On Jun 22, 7:19 pm, SVIX saivivekh.swaminat...@gmail.com wrote: couldn't we just collect

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
ohh sorry my mistake LCS stands for Longest Common Subsequence On Wed, Jun 22, 2011 at 11:21 PM, SVIX saivivekh.swaminat...@gmail.comwrote: ah... i misunderstood the question... sorry.. On Jun 22, 12:01 pm, ankit mehta mehta.bond...@gmail.com wrote: You dont have to create longest

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread abhishek agrawal
http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/ This algo runs in Linear time. On Thu, Jun 23, 2011 at 1:23 AM, sunny agrawal sunny816.i...@gmail.comwrote: ohh sorry my mistake LCS stands for Longest Common Subsequence On Wed, Jun 22, 2011 at 11:21