Given a string str of even size N consisting of lowercase English alphabets. The task is to find the number of rotated strings of str which have more vowels in the first half than the second half.
Input: str = “abcd”
All rotated string are “abcd”, “dabc”, “cdab”, “bcda”.
The first two rotated strings have more vowels in
the first half than the second half.
Input: str = “abecidft”
Approach: An efficient approach is to make string s = str + str then the size of the s will be 2 * N. Now, make a prefix array to store the number of vowels present from the 0th index to the ith index. Then run a loop from N – 1 to 2 * N – 2 to get all the rotated strings of str. Find the count of required rotated strings.
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.
- Count binary strings with twice zeros in first half
- Reorder an array such that sum of left half is not equal to sum of right half
- Find prime numbers in the first half and second half of an array
- Sum of elements in range L-R where first half and second half is filled with odd and even numbers
- Find the sum of the first half and second half elements of an array
- Find the XOR of first half and second half elements of an array
- Sort an Array of Strings according to the number of Vowels in them
- Count of substrings consisting of even number of vowels
- Count the number of vowels occurring in all the substrings of given string
- Python program to count number of vowels using sets in given string
- Generate string with Hamming Distance as half of the hamming distance between strings A and B
- Count strings with consonants and vowels at alternate position
- Longest Even Length Substring such that Sum of First and Second Half is same
- Reduce every element of the array to it's half retaining the sum zero
- Minimum insertions to make XOR of an Array equal to half of its sum
- Check if at least half array is reducible to zero by performing some operations
- Check if the frequency of any character is more than half the length of the string
- Find all even length binary sequences with same sum of first and second half bits | Iterative
- Count number of binary strings of length N having only 0's and 1's
- Count number of strings (made of R, G and B) using given combination
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.