FastPrepCount Vowel Permutations

Count Vowel Permutations

Zscaler logoZscaler● MediumINTERNONSITE INTERVIEW
Learn

Problem statement

Return the number of length-n strings made only from a, e, i, o, and u that follow these rules:

  • a may be followed only by e.
  • e may be followed only by a or i.
  • i may be followed by a, e, o, or u.
  • o may be followed only by i or u.
  • u may be followed only by a.

Return the count modulo 1,000,000,007.

Function

countVowelPermutations(n: int) → int

Examples

Example 1

n = 1return = 5

Every single vowel is valid.

Example 2

n = 2return = 10

The valid transitions are ae, ea, ei, ia, ie, io, iu, oi, ou, ua.

Example 3

n = 5return = 68

Dynamic programming counts valid strings ending in each vowel after five positions.

Constraints

  • 1 <= n <= 20000

More Zscaler problems

See Zscaler hiring insights
public int countVowelPermutations(int n) {
  // write your code here
}
n1
expected5
Checking account…