Ctrl K

The Only Repeat

Easy
A visitor log values holds badge numbers. Every number appears exactly once except one, which is logged twice or more. Return that number. If the repeated number fills exactly half of the log, can you solve it without extra memory?
Example 1
values=[6, 8, 6, 1] → 6

The 6 appears twice and the other numbers once each.

Example 2
values=[7, 0, 4, 7, 9, 7] → 7

The 7 appears three times: the repeated number may show up any number of times.

Example 3
values=[12, 3, 5, 8, 12] → 12
Constraints
  • 2 ≤ len(values) ≤ 10⁵
  • 0 ≤ values[i] ≤ 10⁴
  • Exactly one number appears more than once; every other number appears once
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyRepeat Within Reach EasyThe Lost Ticket Easy
loading Python…
Input
values=[6, 8, 6, 1]
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.