#1220
Count Vowels Permutation
expert · 1155 · lc hard +32 · verified · 61.4% accepted · 3,297 likes · top 61%
Description
Given an integer n, count distinct strings of length n composed only of lowercase vowels ('a', 'e', 'i', 'o', 'u') that obey these transition rules:
- 'a' may only be followed by 'e'.
- 'e' may only be followed by 'a' or 'i'.
- 'i' may not be followed by another 'i'.
- 'o' may only be followed by 'i' or 'u'.
- 'u' may only be followed by 'a'.
Since the answer can be very large, return it modulo 109 + 7.
Example 1:
Input: n = 1
Output: 5
Explanation: All possible strings are: "a", "e", "i" , "o" and "u".
Example 2:
Input: n = 2
Output: 10
Explanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".
Example 3:
Input: n = 5
Output: 68
Code
1
2
3