The Vowel Hunt
An easy Python interview practice problem on DataDriven. Write the Python and run it against test cases, with instant feedback.
- Domain
- Python
- Difficulty
- easy
- Seniority
- L3
- Asked in
- Quantiphi
Problem
Given a string, return the count of vowels: characters a, e, i, o, u (case-insensitive).
Just the vowels. All of them.
Example 1
Input:
s = "Hello World"
Output:
3
Example 2
Input:
s = "AEIOU aeiou"
Output:
10
Worked solution and explanation
Why this problem exists in real interviews
This tests basic string iteration with set membership checks. It is a warm-up problem that reveals whether a candidate handles case-insensitivity correctly and uses a set for O(1) lookups.
Break down the requirements
Step 1: Define the vowel set
Include both lowercase vowels: a, e, i, o, u. Convert each character to lowercase before checking.
Step 2: Iterate and count matches
Loop through each character, check membership in the vowel set, and increment a counter.
The solution
def count_vowels(s: str) -> int:
vowels = {'a', 'e', 'i', 'o', 'u'}
count = 0
for ch in s:
if ch.lower() in vowels:
count += 1
result = count
return resultCommon follow-up questions
- What if 'y' should sometimes count as a vowel? (Tests conditional logic based on character position or surrounding characters.)
- How would you return the positions of all vowels? (Tests collecting indices instead of counting.)
- What if the input was a file with millions of characters? (Tests streaming character-by-character without loading the entire file.)