C3 OA

Gotten this question a few times already this year. All my solutions so far keep timing out.

Question:
How many strings of a given length can be formed under the following rules?

  1. Each letter is a vowel, that is, it is in the set {a,e,i,o,u}
  2. The letter ‘a’ may only be followed by the letter ‘e’.
  3. The letter ‘e’ may only be followed by an ‘a’ or an ‘i’
  4. An ‘i’ may not be next to another ‘i’
  5. The letter ‘o’ may only be be followed by an ‘i’ or a ‘u’
  6. The letter ‘u’ may only be followed by an ‘a’

Input is the length(n) of the string to be generated.

Return the possible permutations of length (n) that follow the rules above. Only the total amount needs to be returned. Not the actual strings.