# The Dominant Signal

> Hottest items in the transaction log. Ties included.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a list of items, return every item that appears at the maximum frequency. If multiple items are tied at the top, include all of them. Sort the result ascending.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **frequency counting with max-value filtering**, the classic "find all modes" pattern. It probes whether a candidate can count, find the max frequency, then filter all items matching that frequency.

---

### Break down the requirements

#### Step 1: Count occurrences of each item

Build a frequency dict from the transaction log.

#### Step 2: Find the maximum frequency

Scan the frequency dict to find the highest count.

#### Step 3: Collect all items with that frequency

Multiple items can tie for the top spot; return all of them.

---

### The solution

**Frequency counting with mode extraction**

```python
def find_modes(items: list) -> list:
    freq = {}
    for item in items:
        if item in freq:
            freq[item] += 1
        else:
            freq[item] = 1
    max_count = 0
    for count in freq.values():
        if count > max_count:
            max_count = count
    modes = []
    for item, count in freq.items():
        if count == max_count:
            modes.append(item)
    return modes
```

> **Time and Space Complexity**
>
> **Time:** O(n) for counting, O(k) for finding the max and filtering, where k is the number of unique items.
> 
> **Space:** O(k) for the frequency dict.

> **Interviewers Watch For**
>
> Whether you handle ties. Returning only one item when multiple share the highest frequency is a common oversight.

> **Common Pitfall**
>
> Using `max()` on the frequency dict keys instead of values. `max(freq)` returns the largest key, not the key with the highest count.

---

## Common follow-up questions

- What if you needed the top-k most frequent items? _(Tests heap or sorted approach for partial ranking.)_
- How would you handle an empty input? _(Tests edge case: return an empty list.)_
- What if the output should be sorted? _(Tests adding a sort step on the result.)_

## Related

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