Given a string str, the task is to check whether every group of consecutive a’s is followed by a group of consecutive b’s of same length. If the condition is true for every group then print 1 else print 0.
Input: str = “ababaabb”
ab, ab, aabb. All groups are valid
Input: str = “aabbabb”
aabb, abb (A single ‘a’ followed by 2 ‘b’)
- For every a in the string increment the count.
- Starting from the first b, decrement the count for every b.
- If at the end of the above cycle, count != 0 then return false.
- Else repeat the first two steps for the rest of the string.
- Return true if the condition is satisfied for all the cycles else print 0.
Below is the implementation of the above approach:
- Group words with same set of characters
- Group Shifted String
- Group all occurrences of characters according to first appearance
- Group consecutive characters of same type in a string
- Minimum swaps to group similar characters side by side?
- Check if all the palindromic sub-strings are of odd length
- Check if a binary string contains all permutations of length k
- Check length of a string is equal to the number appended at its last
- Check if the frequency of any character is more than half the length of the string
- Check if it is possible to reach a number by making jumps of two given length
- Check if a string contains a palindromic sub-string of even length
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Program to find Length of Bridge using Speed and Length of Train
- Run Length Encoding
- Nth Even length Palindrome
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.