# The Solo Act

> One-and-done values only.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a list of integers, return a list of the values that appear exactly once, preserving input order.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **frequency counting** followed by **order-preserving filtering**. It is a two-pass pattern: first count occurrences, then filter to elements that appeared exactly once while maintaining original order.

---

### Break down the requirements

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

Build a frequency dict in one pass over the list.

#### Step 2: Filter to codes with count exactly 1, preserving order

Iterate the original list a second time, collecting codes whose count is 1.

---

### The solution

**Two-pass frequency filter**

```python
def find_singletons(codes: list) -> list:
    counts = {}
    for code in codes:
        counts[code] = counts.get(code, 0) + 1
    result = []
    for code in codes:
        if counts[code] == 1:
            result.append(code)
    return result
```

> **Time and Space Complexity**
>
> **Time:** O(n) for two passes over the list. Dict operations are O(1) average.
> 
> **Space:** O(n) for the frequency dict and result list.

> **Interviewers Watch For**
>
> The two-pass approach cleanly separates counting from filtering. Candidates who try to do both in one pass often produce incorrect order or miss edge cases.

> **Common Pitfall**
>
> Using `list.count()` inside the second loop makes it O(n^2). Always pre-compute frequencies in a dict.

---

## Common follow-up questions

- What if you needed singletons in sorted order instead of original order? _(Tests adding a sort step after filtering.)_
- How would you find the first singleton only? _(Tests short-circuiting the second pass after the first match.)_
- What if the input stream was too large to fit in memory? _(Tests external sorting or streaming frequency estimation techniques.)_

## Related

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