← run

he-026

1.000
1/1 tests· basic
Challenge · difficulty 1/5
# HumanEval/26

Implement a file **`solution.py`** that completes the function below. Keep the given name and signature; your file must define it at module level.

```python
from typing import List


def remove_duplicates(numbers: List[int]) -> List[int]:
    """ From a list of integers, remove all elements that occur more than once.
    Keep order of elements left the same as in the input.
    >>> remove_duplicates([1, 2, 3, 2, 4])
    [1, 3, 4]
    """
```

<!-- imported from OpenAI HumanEval (HumanEval/26) -->
tests/test_he_026.py
# Auto-generated from OpenAI HumanEval HumanEval/26. Do not edit by hand.
from solution import *  # noqa: F401,F403 (prompt helpers may be referenced by tests)
from solution import remove_duplicates as candidate

METADATA = {
    'author': 'jt',
    'dataset': 'test'
}


def check(candidate):
    assert candidate([]) == []
    assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4]
    assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]


def test_he_026():
    check(candidate)
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.
Proposed solution
```python
from typing import List
from collections import Counter


def remove_duplicates(numbers: List[int]) -> List[int]:
    """ From a list of integers, remove all elements that occur more than once.
    Keep order of elements left the same as in the input.
    >>> remove_duplicates([1, 2, 3, 2, 4])
    [1, 3, 4]
    """
    counts = Counter(numbers)
    return [n for n in numbers if counts[n] == 1]
```

Test output (stdout)

.                                                                        [100%]
1 passed in 0.01s
Reasoning (chain-of-thought)
The user wants me to implement a function `remove_duplicates` that:
- Takes a list of integers
- Removes all elements that occur more than once
- Keeps the order of remaining elements the same as in the input

So if an element appears exactly once, it stays. If it appears 2+ times, all instances are removed.

Example: `[1, 2, 3, 2, 4]`
- 1 appears once → keep
- 2 appears twice → remove both
- 3 appears once → keep
- 4 appears once → keep
Result: `[1, 3, 4]`

Approach:
1. Count occurrences of each element
2. Filter to keep only elements with count == 1

Let me implement this:

```python
from typing import List
from collections import Counter

def remove_duplicates(numbers: List[int]) -> List[int]:
    counts = Counter(numbers)
    return [n for n in numbers if counts[n] == 1]
```

This is clean and correct. Let me verify with the example:
- counts = {1: 1, 2: 2, 3: 1, 4: 1}
- Filter: 1 (count 1, keep), 2 (count 2, skip), 3 (count 1, keep), 2 (count 2, skip), 4 (count 1, keep)
- Result: [1, 3, 4] ✓