# The Silver Screen Summit

> Box office totals decide who makes the top of the marquee.

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

Domain: Python · Difficulty: medium · Seniority: L3

## Problem

Given movies (list of dicts with 'actor' and 'earnings') and integer n, sum earnings per actor, then return the n actors with the largest totals sorted by total descending, tie-break alphabetically.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **dict-based aggregation** and **sorting by computed values**, a pattern that mirrors GROUP BY + ORDER BY in SQL. It probes whether a candidate can accumulate totals and then extract the top N entries efficiently.

---

### Break down the requirements

#### Step 1: Aggregate earnings by actor name

Iterate through movie records, accumulating each actor's total box office earnings in a dict.

#### Step 2: Sort actors by total earnings descending

Convert the dict to a sortable structure and sort by value in descending order.

#### Step 3: Return the top N actor names

Slice the sorted list to get the first N entries and extract just the names.

---

### The solution

**Dict aggregation with sorted extraction**

```python
def top_actors(movies: list, n: int) -> list:
    earnings = {}
    for movie in movies:
        actor = movie["actor"]
        box_office = movie["earnings"]
        earnings[actor] = earnings.get(actor, 0) + box_office
    sorted_actors = sorted(earnings.items(), key=lambda x: x[1], reverse=True)
    result = []
    for i in range(min(n, len(sorted_actors))):
        result.append(sorted_actors[i][0])
    return result
```

> **Time and Space Complexity**
>
> **Time:** O(m log m + r) where r is the number of movie records and m is the number of unique actors. Aggregation is O(r), sorting is O(m log m).
> 
> **Space:** O(m) for the earnings dict.

> **Interviewers Watch For**
>
> Using `dict.get(key, 0)` for safe accumulation instead of checking `if key in dict` shows fluency with Python dict idioms.

> **Common Pitfall**
>
> Sorting the entire dict when you only need top N. For large datasets, `heapq.nlargest` is O(m log n) which beats full sort, but interviewers rarely penalize the sort approach for clarity.

---

## Common follow-up questions

- How would you handle ties at the Nth position? _(Tests whether you include all tied actors or strictly limit to N.)_
- What if movie records could have missing earnings fields? _(Tests defensive access patterns with `.get()` or try/except.)_
- How would you optimize if N is much smaller than the number of actors? _(Tests knowledge of heap-based selection: `heapq.nlargest(n, ...)` avoids full sort.)_

## Related

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