Created
March 24, 2012 21:39
-
-
Save joshbuddy/2188292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For an arbitrary string, detect the largest palindrome* present within it. | |
* a sequence of characters the same forwards and backwards at least 3 characters long. | |
For instance in "abbabcdedc", the longest palindrome would be "cdedc". | |
Answers? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's something in Haskell. I tried to decompose the problem into 1. make substrings, 2. filter out non palindromes, then 3. find the longest string.
substrings
time complexity grows like a Trianglular number. I thinkpalindrome
andlongest
are both O(n).Usage:
longest (palindromes "abbabcdedc")