java.lang.Object
g1201_1300.s1220_count_vowels_permutation.Solution

public class Solution extends Object
1220 - Count Vowels Permutation.<p>Hard</p> <p>Given an integer <code>n</code>, your task is to count how many strings of length <code>n</code> can be formed under the following rules:</p> <ul> <li>Each character is a lower case vowel (<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'</code>)</li> <li>Each vowel <code>'a'</code> may only be followed by an <code>'e'</code>.</li> <li>Each vowel <code>'e'</code> may only be followed by an <code>'a'</code> or an <code>'i'</code>.</li> <li>Each vowel <code>'i'</code> <strong>may not</strong> be followed by another <code>'i'</code>.</li> <li>Each vowel <code>'o'</code> may only be followed by an <code>'i'</code> or a <code>'u'</code>.</li> <li>Each vowel <code>'u'</code> may only be followed by an <code>'a'.</code></li> </ul> <p>Since the answer may be too large, return it modulo <code>10^9 + 7.</code></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 1</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> All possible strings are: &ldquo;a&rdquo;, &ldquo;e&rdquo;, &ldquo;i&rdquo; , &ldquo;o&rdquo; and &ldquo;u&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 2</p> <p><strong>Output:</strong> 10</p> <p><strong>Explanation:</strong> All possible strings are: &ldquo;ae&rdquo;, &ldquo;ea&rdquo;, &ldquo;ei&rdquo;, &ldquo;ia&rdquo;, &ldquo;ie&rdquo;, &ldquo;io&rdquo;, &ldquo;iu&rdquo;, &ldquo;oi&rdquo;, &ldquo;ou&rdquo; and &ldquo;ua&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 5</p> <p><strong>Output:</strong> 68</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 2 * 10^4</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countVowelPermutation

      public int countVowelPermutation(int n)