# The Crowd Splitter

> The middle holds even with a dominant outlier.

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

Domain: Python · Difficulty: easy · Seniority: L4

## Problem

Given a list of integers where one value appears strictly more than half the time, return its value. The median equals that dominant value.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests whether a candidate recognizes that a **majority element is always the median** of the list. It probes algorithmic insight: if one value dominates more than half the positions, it must occupy the center after sorting.

---

### Break down the requirements

#### Step 1: Sort the list

With a majority element guaranteed, the median position is always occupied by that element.

#### Step 2: Return the middle element

Index `len(nums) // 2` gives the median. The majority element is guaranteed to be there.

---

### The solution

**Sort and pick the median**

```python
def find_median(nums: list) -> int:
    sorted_nums = sorted(nums)
    median = sorted_nums[len(sorted_nums) // 2]
    return median
```

> **Time and Space Complexity**
>
> **Time:** O(n log n) for sorting. An O(n) solution exists using Boyer-Moore voting or quickselect.
> 
> **Space:** O(n) for the sorted copy.

> **Interviewers Watch For**
>
> Whether you mention that an O(n) solution is possible. Sorting is acceptable, but acknowledging the optimal approach shows deeper understanding.

> **Common Pitfall**
>
> Using the wrong median index. For a list of length n, `n // 2` gives the correct position for both even and odd lengths when a majority element is guaranteed.

---

## Common follow-up questions

- How would you find the median without sorting? _(Tests quickselect algorithm or Boyer-Moore for the majority case.)_
- What if no majority element exists? _(Tests that the median-equals-majority shortcut no longer applies.)_
- What is the space complexity of quickselect? _(Tests O(1) for in-place partition vs O(n) for the sorted-copy approach.)_

## Related

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