Given a string str, the task is to find the minimum length of substring required to rotate that generates a palindromic substring from the given string.
Input: str = “abcbd”
Explanation: No palindromic substring can be generated there is no repeating character in the string.
Input: str = “abcdeba”
Explanation: Rotate substring “deb” to convert the given string to abcbeda with a palindromic substring “bcb”.
- If no character repeats in the string, then no palindromic substring can be generated.
- For every repeating character, check if the index of its previous occurrence is within one or two indices from the current index. If so, then a palindromic substring already exists.
- Otherwise, calculate the length of (current index – index of previous occurrence – 1).
- Return the minimum of all such lengths as the answer
Below is the implementation of the above approach:
Time Complexity: O(N)
- Maximum length palindromic substring such that it starts and ends with given char
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Minimum length substring with exactly K distinct characters
- Minimum K such that every substring of length atleast K contains a character c
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Shortest Palindromic Substring
- Longest Non-palindromic substring
- Longest Palindromic Substring | Set 1
- Longest Palindromic Substring | Set 2
- Longest palindromic string possible after removal of a substring
- Check if a substring can be Palindromic by replacing K characters for Q queries
- Suffix Tree Application 6 - Longest Palindromic Substring
- Construct a string of length L such that each substring of length X has exactly Y distinct letters
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 1
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 4
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 3
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 2
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Length of the smallest substring which contains all vowels
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.