Count Vowels Permutation - Problem
Given an integer n, your task is to count how many strings of length n can be formed under the following rules:
- Each character is a lower case vowel (
'a','e','i','o','u') - Each vowel
'a'may only be followed by an'e' - Each vowel
'e'may only be followed by an'a'or an'i' - Each vowel
'i'may not be followed by another'i' - Each vowel
'o'may only be followed by an'i'or a'u' - Each vowel
'u'may only be followed by an'a'
Since the answer may be too large, return it modulo 10⁹ + 7.
Input & Output
Example 1 — Small Input
$
Input:
n = 1
›
Output:
5
💡 Note:
For length 1, all vowels are valid: 'a', 'e', 'i', 'o', 'u'. Total = 5 strings.
Example 2 — Medium Input
$
Input:
n = 2
›
Output:
10
💡 Note:
Valid strings: 'ae', 'ea', 'ei', 'ia', 'ie', 'io', 'iu', 'oi', 'ou', 'ua'. Total = 10 strings.
Example 3 — Larger Input
$
Input:
n = 5
›
Output:
68
💡 Note:
Following the transition rules through 5 levels, we get 68 valid vowel permutation strings.
Constraints
- 1 ≤ n ≤ 2 × 104
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code