The Count Vowel Strings in Ranges interview question gives you an array of strings and several range queries. A string is considered a "vowel string" if it both starts and ends with a vowel (a, e, i, o, u). For each query [left, right], you must count how many vowel strings exist in the array between those indices (inclusive).
Microsoft and PayPal ask the Count Vowel Strings in Ranges coding problem to test a candidate's ability to handle multiple queries efficiently. A brute-force approach (looping through the range for every query) results in O(n * q) time complexity, which is unacceptable for large datasets. It assesses your knowledge of the Prefix Sum technique, which is a fundamental tool for O(1) range query processing.
The primary interview pattern here is the Prefix Sum.
isVowel[i] is 1 if the string starts and ends with a vowel, and 0 otherwise.P where P[i] is the total count of vowel strings from index 0 to i-1.[L, R], the answer is simply P[R+1] - P[L].Words: ["aba", "bcb", "ece", "aa", "e"], Query: [0, 2]
[1, 0, 1, 1, 1][0, 1, 1, 2, 3, 4][0, 2]: P[3] - P[0] = 2 - 0 = 2.
The strings are "aba" and "ece".Whenever you encounter a problem involving "Sum of property in range [L, R]" with many queries, think of Prefix Sums immediately. It reduces time complexity from O(N) per query to O(1) after O(N) preprocessing.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Number of Operations to Move All Balls to Each Box | Medium | Solve | |
| Shifting Letters | Medium | Solve | |
| Minimum Amount of Time to Collect Garbage | Medium | Solve | |
| Shifting Letters II | Medium | Solve | |
| Shift Distance Between Two Strings | Medium | Solve |