# Program to count sorted vowel strings in Python

PythonServer Side ProgrammingProgramming

Suppose we have a number n, we have to find the number of strings of size n that consist only of vowels (a, e, i, o, u) and they are lexicographically sorted. We can say that a string s is lexicographically sorted when for all valid index i, s[i] is the same as or comes before s[i+1] in the alphabet.

So, if the input is like n = 2, then the output will be 15 because there are many strings like ["aa", "ae", "ai", "ao", "au", "ee", "ei", "eo", "eu", "ii", "io", "iu", "oo", "ou", "uu"].

To solve this, we will follow these steps −

• if n is same as 1, then
• return 5
• count := an array of size 6, and initially filled with 1
• for i in range 3 to n, do
• count := count+count+count+count+count
• count := count+count+count+count
• count := count+count+count
• count := count+count
• total := 0
• for i in range 1 to 5, do
• total := total + i*count[i]

## Example

Let us see the following implementation to get better understanding −

def solve(n):
if n==1:
return 5
count = [1 for i in range(6)]
for i in range(3,n+1):
count = count+count+count+count+count
count = count+count+count+count
count = count+count+count
count = count+count
total = 0
for i in range(1,6):
total += i*count[i]
print(solve(n))
2
15