Skip to content

Repeated Value Check

Easy#hash-set#single-pass~10 min

The mission

Problem

Given a list of values, decide whether any value shows up more than once. Return true if at least one value repeats anywhere in the list, and false when every value is unique. The repeats do not have to be next to each other.

Examples

Input:  items = [4, 1, 9, 1]
Output: True
Why:    the value 1 appears at two different positions
Input:  items = [4, 1, 9]
Output: False
Why:    all three values differ
Input:  items = []
Output: False
Why:    edge case, an empty list cannot contain a repeat

Hints

0 / 3

Target time
O(n)
Target space
O(n)

Stuck on the idea rather than the code? Frequency Counting covers it.

Python 3Ctrl+Enter runs
Custom test case