# The Vowel Hunt

> Just the vowels. All of them.

Canonical URL: <https://datadriven.io/problems/the_vowel_hunt>

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a string, return the count of vowels: characters a, e, i, o, u (case-insensitive).

## 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

**Set lookup with case normalization**

```python
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 result
```

> **Time and Space Complexity**
>
> **Time:** O(n) where n is the length of the string.
> 
> **Space:** O(1). The vowel set is a fixed size of 5.

> **Interviewers Watch For**
>
> Using a set for vowels instead of a string. While `'aeiou'.__contains__` works, a set makes the O(1) intent explicit.

> **Common Pitfall**
>
> Checking only lowercase or only uppercase vowels. The `.lower()` conversion ensures both cases are handled.

---

## Common 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.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/the_vowel_hunt)
- [Python Interview Questions](https://datadriven.io/python-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.