Given a string S of lowercase English alphabets, the task is to check if there exists an arrangement of string S such that it doesn’t contain any monotonous substring.
A monotonous substring has the following properties:
- Length os such substring is 2.
- Both the characters are consecutive, For example – “ab”, “cd”, “dc”, “zy” etc.
Input: S = “abcd”
String S can be rearranged into “cadb” or “bdac”
Input: string = “aab”
Every arrangement of the string contains a monotonous substring.
Approach: The idea is group the characters into two different buckets, where one bucket contains the characters which are at the even places and another bucket contains the characters which are at the odd places. Finally, check for the concatenation point of both the group is not a monotonous 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.
- Queries to check if string B exists as substring in string A
- Check if any permutation of string is a K times repeated string
- Check if given string is a substring of string formed by repeated concatenation of z to a
- Check if a string is substring of another
- Check if the given string is shuffled substring of another string
- Check if permutaion of one string can break permutation of another
- Check if there exists any sub-sequence in a string which is not palindrome
- Python | Check if a Substring is Present in a Given String
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Check if string can be made lexicographically smaller by reversing any substring
- Smallest non-zero substring which has any permutation divisible by 2^K
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Find length of longest subsequence of one string which is substring of another string
- Minimum length of string having all permutation of given string.
- Minimum changes required to make first string substring of second string
- Smallest String consisting of a String S exactly K times as a Substring
- Check if two strings are permutation of each other
- Check if any permutation of N equals any power of K
- Check if the given permutation is a valid BFS of a given Tree
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.