Amazon.com

  www.amazon.com
Work in HR? Unlock Free Profile

Amazon.com Software Engineer Intern Interview Question

"Find the largest palindrome in a given word."
Add Tags [?]
Answer

Part of a Software Engineer Intern Interview Review - one of 4,635 Amazon.com Interview Reviews

Answers & Comments

0
of 0
votes
Assume a single character is a palindrome of size 1. To begin, iterate starting at the beginning of the list. If element[i-1] == element[i+1], then continue continue checking with 1 replaced with 2, and so forth. Eventually you'll arrive at a contradiction; set currentBest accordingly. Continue to end of list, replacing currentBest as needed.

One optimization, if (currentMax/2 > arrayLength - i) then stop searching; It is impossible to find a longer palindrome with the remaining portion of the list.
- Anonymous on Apr 24, 2011
0
of 0
votes
Good old Suffix tree.
- Gee on Sep 28, 2011

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.