Given a string of lowercase, find the length of the longest substring that does not contain any palindrome as a substring.
Input : str = "daiict" Output : 3 dai, ict are longest substring that do not contain any palindrome as substring Input : str = "a" Output : 0 a is itself a palindrome
The idea is to observe that if any character forms a palindrome, it can not be included in any substring. So, in that case required substring will be picked from before or after that character which forms a palindrome.
Therefore, a simple solution is to traverse the string and for each character check whether it forms a palindrome of length 2 or 3 with its adjacent characters. If, does not then increase the length of substring otherwise re-initialize the length of the substring to zero. Using this approach find the length of the maximum substring.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if there exists a permutation of given string which doesn't contain any monotonous substring
- Length of Longest Palindrome Substring
- Next word that does not contain a palindrome and has characters from first k
- DFA that begins with 'a' but does not contain substring 'aab'
- Count the nodes of a tree whose weighted string does not contain any duplicate characters
- Check if a String contains Anagrams of length K which does not contain the character X
- Longest substring whose characters can be rearranged to form a Palindrome
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Minimum length of substring whose rotation generates a palindromic substring
- Queries to check if substring[L...R] is palindrome or not
- Longest substring between any pair of occurrences ōf similar characters
- To check a number is palindrome or not without using any extra space
- Check if there exists any sub-sequence in a string which is not palindrome
- Check if sum of any subarray is Palindrome or not
- Check if any anagram of a string is palindrome or not
- Length of longest palindrome list in a linked list using O(1) extra space
- Longest palindrome formed by concatenating and reordering strings of equal length
- Length of the longest substring without repeating characters
- Longest Even Length Substring such that Sum of First and Second Half is same
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.