# The Deep Dictionary

> One key goes further than the rest.

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

Domain: Python · Difficulty: easy · Seniority: L6

## Problem

Given a dict mapping names to lists of review scores, return the name whose list is longest. If multiple tie, return the alphabetically first name.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests the same pattern as finding a max-by-value in a dict, but framed around review counts. It probes whether a candidate can iterate dict items and track the key with the highest value efficiently.

---

### Break down the requirements

#### Step 1: Iterate through dict items

Each key is a name, each value is the review count.

#### Step 2: Track the name with the highest count

Compare each count against the running maximum and update the winner.

---

### The solution

**Linear scan for maximum value key**

```python
def most_reviewed(data: dict) -> str:
    best_name = ""
    best_count = -1
    for name, count in data.items():
        if count > best_count:
            best_count = count
            best_name = name
    return best_name
```

> **Time and Space Complexity**
>
> **Time:** O(n) where n is the number of entries.
> 
> **Space:** O(1) extra space.

> **Interviewers Watch For**
>
> Whether you use `max(data, key=data.get)` or write the explicit loop. Both are valid, but the loop proves understanding.

> **Common Pitfall**
>
> Returning the count instead of the name. Read the return type carefully.

---

## Common follow-up questions

- What if ties should return all winners? _(Tests collecting all names sharing the max count.)_
- What if data values were lists and you needed to compare by list length? _(Tests using `len(v)` as the comparison metric.)_
- How would you find the top-k names? _(Tests sorting or heap-based selection.)_

## Related

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