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:
- String formed with middle character of every right substring followed by left sequentially
- Check if a string can be split into substrings starting with N followed by N characters
- Decode a string recursively encoded as count followed by substring
- Rearrange a string in sorted order followed by the integer sum
- Rearrange a string in the form of integer sum followed by the minimized character
- Print 2-D co-ordinate points in ascending order followed by their frequencies
- Length of longest Palindromic Subsequence of even length with no two adjacent characters same
- Check whether two strings contain same characters in same order
- Group words with same set of characters
- Group consecutive characters of same type in a string
- Minimum Group Flips to Make Binary Array Elements Same
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Map every character of one string to another such that all occurrences are mapped to the same character
- Maximize product of same-indexed elements of same size subsequences
- Minimum K such that every substring of length atleast K contains a character c
- Replace every consonant sequence with its length in the given string
- Count of distinct permutations of every possible length of given string
- Longest Even Length Substring such that Sum of First and Second Half is same
- Find all even length binary sequences with same sum of first and second half bits
- Maximum length substring having all same characters after k changes
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.