# The Crowd Favorite Eatery

> One restaurant clearly won the most hearts.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a dict mapping restaurant names to lists of review strings, return the restaurant with the most reviews (len of its list). If multiple tie, return the alphabetically first restaurant name.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **dict iteration with max-by-value logic**. It probes whether a candidate can find the key with the largest associated collection efficiently, using `len()` as the comparison metric.

---

### Break down the requirements

#### Step 1: Iterate through the dict items

Compare the length of each restaurant's review list to track the current maximum.

#### Step 2: Track the winner and max count

Maintain variables for the best restaurant name and its review count.

#### Step 3: Return the winner

Ties can return either name, so no tiebreaking logic is needed.

---

### The solution

**Linear scan for max review count**

```python
def most_reviewed(restaurants: dict) -> str:
    best_name = ""
    best_count = -1
    for name, reviews in restaurants.items():
        count = len(reviews)
        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 restaurants. Computing `len()` on a list is O(1).
> 
> **Space:** O(1) extra space beyond the input.

> **Interviewers Watch For**
>
> Whether you call `len()` on each list vs iterating through reviews to count them manually. Using `len()` is the correct approach since Python lists track their size internally.

> **Common Pitfall**
>
> Using `max()` with a key function is fine, but interviewers may want to see the explicit loop to verify you understand the underlying comparison.

---

## Common follow-up questions

- What if you also needed the average rating? _(Tests combining length and sum in the same pass.)_
- How would you handle an empty input dict? _(Tests edge case: returning `None` or raising an error.)_
- What if ties should be broken alphabetically? _(Tests adding a secondary comparison condition.)_

## Related

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