Given a string str and a character ch, the task is to find the longest palindromic sub-string of str such that it starts and ends with the given character ch.
Input: str = “lapqooqpqpl”, ch = ‘p’
“pqooqp” is the maximum length palindromic
sub-string that starts and ends with ‘p’.
Input: str = “geeksforgeeks”, ch = ‘k’
“k” is the valid sub-string.
Approach: For every possible index pair (i, j) such that str[i] = str[j] = ch check whether the sub-string str[i…j] is palindrome or not. For all the found palindromes, store the length of the longest palindrome found so far.
Below is the implementation of the above approach:
- Maximum length substring having all same characters after k changes
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Maximum length substring with highest frequency in a string
- Count substrings that starts with character X and ends with character Y
- Find if a string starts and ends with another given string
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Longest Non-palindromic substring
- Longest Palindromic Substring | Set 2
- Longest Palindromic Substring | Set 1
- Suffix Tree Application 6 - Longest Palindromic Substring
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 4
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 2
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 1
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 3
- Sum of all odd length palindromic numbers within the range [L, R]
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.