There are many problems about string, including substr
implementation, validating palindrome and common substring and so on. Essentially, a string is also an array of characters. So, many ideas of array can be used to solve the problems of string.
There are many algorithms which specifically used for handle strings. Such as trie
, huffman tree
, Manacher
and so on.
This kind of questions are the most direct ones with less ambiguous meanings and less challenging. So, it is always be used in the phone interviews.
A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward. Like "level" and "noon".
There is universal method to check whether a string is palindrome or not which uses two pointers, one at the begining and the other at the end, to move to the middle together step by step. You can check the following question 125
for more detials.
For finding the longest palindrome, it is possible to reduce many meaningless algorithms if we take full advantage of the feature of palindrome. Manacher's algorithm is a typical example.
It is intuitive to use prefix tree to handle this kind of questions. But it also has some disadvantages. For example, if there are less common prefix, using prefix tree may cost more RAMs.