Closest Vowels solution codechef

Closest Vowels solution codechef

Chef considers a string consisting of lowercase English alphabets beautiful if all the characters of the string are vowels.

Chef has a string SS consisting of lowercase English alphabets, of length NN. He wants to convert SS into a beautiful string TT. In order to do so, Chef does the following operation on every character of the string:

  • If the character is a consonant, change the character to its closest vowel.
  • If the character is a vowel, don’t change it.

Chef realizes that the final string TT is not unique. Chef wonders, what is the total number of distinct beautiful strings TT that can be obtained by performing the given operations on the string SS.

Since the answer can be huge, print it modulo 109+7109+7.

Note:

Closest Vowels solution codechef

  • There are 2626 characters in the English alphabet. Five of these characters are vowels: aeio, and u. The remaining 2121 characters are consonants.
  • The closest vowel to a consonant is the vowel that is least distant from that consonant. For example, the distance between the characters d and e is 11 while the distance between the characters d and a is 33.
  • The distance between the characters z and a is 2525 and not 11.
  • CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef, we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month.

Input Format

  • The first line of input will contain an integer TT — the number of test cases. The description of TT test cases follows.
  • The first line of each test case contains an integer NN, denoting the length of the string SS.
  • The second line of each test case contains a string SS consisting of lowercase English alphabets.

Output Format

Closest Vowels solution codechef

For each test case, output the total number of distinct beautiful strings TT that can be obtained by performing the given operations on the string SS, modulo 109+7109+7.

Constraints

  • 1T10001≤T≤1000
  • 1N1051≤N≤105
  • Sum of NN over all test cases does not exceed 105105.

Sample Input 1

Closest Vowels solution codechef

4
5
aeiou
5
abcde
8
starters
8
codechef

Sample Output 1 

1
2
4
4

Explanation

Closest Vowels solution codechef

Test case 11: All the characters of the string SS are vowels. Thus, none of the characters would be changed. The resulting string TT will be aeiou.

Test case 22:There are 22 possible strings that can be obtained by performing the given operations on the string SS. Those are aaaee and aaeee.

SOLUTION

Click here

Leave a Comment

Your email address will not be published.