Skip to content
DeepForgeby svx
All problems
MediumAlgorithmsal-291

Count Sorted Vowel Strings

Problem

Count the strings of length n over the vowels a, e, i, o and u that are non-decreasing in alphabetical order.

The count equals the number of ways to choose n items from 5 types with repetition, which is C(n + 4, 4). Compute it with the multiplicative formula and integer division.

Hint

A non-decreasing string is determined by how many of each vowel it contains.

Test cases

case 1
in: [1]
expected: 5
case 2
in: [2]
expected: 15
case 3
in: [3]
expected: 35
case 4
in: [5]
expected: 126
case 5
in: [10]
expected: 1001
Starter codePython
def count_sorted_vowel_strings(n):
    # Your code here
    pass

5 test cases · run your code against them in the editor