NUMOFPAL - Number of Palindromes
Each palindrome can be always created from the other palindromes, if a single character is also a palindrome. For example, the string "malayalam" can be created by some ways:
* malayalam = m + ala + y + ala + m
* malayalam = m + a + l + aya + l + a + m
We want to take the value of function NumPal(s) which is the number of different palindromes that can be created using the string S by the above method. If the same palindrome occurs more than once then all of them should be counted separately.
The string S.
The value of function NumPal(s).
0 < |s| <= 1000
O(n*n) passes, try MSUBSTR (a bit harder) after this.
O(n) solution can survive better constraints! :)
if u find it difficult, read the problem again :)
Simple Memoisation :)
nice problem to try out palindromic tree :)
0.0 manacher's rox
Last edit: 2016-10-03 22:37:01
will the initial string be a palindrome ??