Given a string str of lowercase alphabets, the task is to find all distinct palindromic sub-strings of the given string.
Input: str = “abaaa”
Palindromic sub-strings are “a”, “aa”, “aaa”, “aba” and “b”
Input: str = “abcd”
Approach: The solution to this problem has been discussed here using Manacher’s algorithm. However we can also solve it using dynamic programming.
Create an array dp where dp[i][j] is set to 1 if str[i…j] is a palindrome else 0. After the array has been generated, store all the palindromic sub-strings in a map in order to get the count of distinct sub-strings.
Below is the implementation of the above approach:
- Rearrange the string to maximize the number of palindromic substrings
- Minimum changes to a string to make all substrings distinct
- Find all distinct palindromic sub-strings of a given string
- Count of distinct substrings of a string using Suffix Trie
- Count of distinct substrings of a string using Suffix Array
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Count of Palindromic substrings in an Index range
- Count all Prime Length Palindromic Substrings
- Make palindromic string non-palindromic by rearranging its letters
- Count distinct substrings that contain some characters at most k times
- Count number of substrings with exactly k distinct characters
- Dynamic Programming on Trees | Set 2
- Dynamic Programming on Trees | Set-1
- Bitmasking and Dynamic Programming | Set-2 (TSP)
- Find the count of palindromic sub-string of a string in its sorted form
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.