Count Sorted Vowel Strings

Given an integer `n`, return the number of strings of length `n` that consist only of the vowels `a`, `e`, `i`, `o`, `u` and are lexicographically sorted. A string is sorted when every character is the same as or comes before the next one in the alphabet.

30:00

Count Sorted Vowel Strings
medium
Free written solution
Topics
Companies

Given an integer n, return the number of strings of length n that consist only of the vowels a, e, i, o, u and are lexicographically sorted. A string is sorted when every character is the same as or comes before the next one in the alphabet.

Example 1:
Input: {"n":1}
Output: 5
Constraints:
  • 1≤n≤501 \leq n \leq 50

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":1}

dp[v] = sorted strings of the row's length that start with vowel v (target n = 1)

length
a
e
i
o
u
total
L=1
1
1
1
1
1
…

Length 1: exactly one string starts with each vowel ("a", "e", "i", "o", "u"), so dp = [1,1,1,1,1]. dp[v] counts sorted strings that start with vowel v.

Variables
VariableValue
length1
dp[1,1,1,1,1]
DepthFunction Call
Stack empty
0/3