# Normalize Name

> Names are messy. Standardize them.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a string, return it with the first letter of each whitespace-separated word capitalized and the rest lowercased.

## Worked solution and explanation

### Why this problem exists in real interviews

Title-casing a name string tests **string method knowledge** and whether you know that Python's `str.title()` exists or can implement it manually. It is a simple ETL normalization check.

---

### Break down the requirements

#### Step 1: Split the name into words

Use whitespace splitting to isolate individual words.

#### Step 2: Capitalize the first letter of each word and lowercase the rest

Apply `word[0].upper() + word[1:].lower()` to each word.

#### Step 3: Rejoin with spaces

Concatenate the title-cased words back into a single string.

---

### The solution

**Manual title-case with split, transform, and rejoin**

```python
def normalize_name(name):
    words = name.split()
    result_words = []
    for word in words:
        titled = word[0].upper() + word[1:].lower()
        result_words.append(titled)
    result = ' '.join(result_words)
    return result
```

> **Time and Space Complexity**
>
> **Time:** O(n) where n is the string length. Split, transform, and join are all linear.
> 
> **Space:** O(n) for the word list and the result string.

> **Interviewers Watch For**
>
> Whether you mention `str.title()` as a built-in. If the interviewer allows it, using `name.title()` is a one-liner. If not, the manual approach shows you understand the operation.

> **Common Pitfall**
>
> `str.title()` has edge cases with apostrophes: `"o'brien".title()` produces `"O'Brien"` which is correct, but `"mcdonald".title()` produces `"Mcdonald"` instead of `"McDonald"`. The prompt likely expects the simple case.

---

## Common follow-up questions

- What if names contain hyphens like 'smith-jones'? _(Tests splitting on both spaces and hyphens for compound names.)_
- What about particles like 'de', 'von', 'van' that stay lowercase? _(Tests a lookup set of exceptions that should not be capitalized.)_
- What if the input has extra whitespace? _(Tests that split() without arguments handles multiple spaces and leading/trailing whitespace.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/normalize_name)
- [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.