Count Vowel Permutations
Reported by candidates from Zscaler's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure this one hinges on is tiny: five integers. Zscaler reported this OA in September 2024, and it's Count Vowel Permutations, a counting DP in disguise. You need the number of length-n strings over a, e, i, o, u where each vowel can only be followed by certain others, modulo 1,000,000,007. With n up to 20000, brute force dies fast. If you're taking this in the next day or two, learn the transition table cold. And if your mind goes blank mid-assessment, StealthCoder runs invisibly on your screen as a safety net and hands you the recurrence.
The problem
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 = 1 return = 5 Every single vowel is valid. Example 2 n = 2 return = 10 The valid transitions are ae, ea, ei, ia, ie, io, iu, oi, ou, ua. Example 3 n = 5 return = 68 Dynamic programming counts valid strings ending in each vowel after five positions. Constraints 1 <= n <= 20000
Reported by candidates. Source: FastPrep
Pattern and pitfall
Track five counts: how many valid strings of the current length end in a, e, i, o, u. Start with all ones for n = 1. Each step, flip the rules around and ask who can precede each vowel. New a = e + i + u. New e = a + i. New i = e + o. New o = i. New u = i + o. Apply modulo on every addition. Answer is the sum of the five after n-1 steps. That's O(n) time and O(1) space. The common pitfall is encoding the rules in the wrong direction, using who a vowel can be followed by instead of who can come before it. Another is forgetting the modulo until the end, which overflows in fixed-width languages. Check your recurrence against n = 2 giving 10 and n = 5 giving 68. If you freeze on the live OA, StealthCoder can supply the transition setup while you verify those examples.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Count Vowel Permutations cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as count vowels permutation. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Zscaler's OA.
Zscaler reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Vowel Permutations FAQ
What's the trick to Count Vowel Permutations?+
Keep five running counts, one per ending vowel. Each new length is built from the previous one by reversing the rules: for each vowel, sum the counts of vowels allowed to come right before it. No need to store strings or a full table.
How hard is this problem really?+
Medium, and on the easier side of medium. The state is only five numbers and the transitions are given. Most people who struggle just mix up the direction of the rules or forget modulo. Once you see it as counting by last character, it's about ten lines.
Is this DP pattern still asked in 2024 OAs?+
Yes. Zscaler candidates reported it in September 2024. Counting-by-ending-state DP shows up constantly because it's short to code but easy to get wrong under pressure. Expect similar problems with a different alphabet or different transition rules.
How do I verify my solution quickly?+
Run the three given examples by hand. n = 1 should return 5, n = 2 should return 10, and n = 5 should return 68. If n = 2 gives 10 but n = 5 is off, your transitions have one wrong edge. Recheck each vowel's predecessors.
Do I need to worry about overflow or large n?+
Take modulo 1,000,000,007 after every addition. With n up to 20000 the numbers explode without it. Use a 64-bit integer in languages with fixed-width ints. A linear loop over 20000 steps is trivially fast, so no matrix exponentiation is needed.