Ctrl K

The Unpaired Value

Easy
In a warehouse every part is stored in pairs, except for one that lost its partner. You get an integer array values in which every value appears exactly twice, except for one value that appears exactly once. Return that lonely value. Aim for linear time and O(1) extra memory.
Example 1
values=[7, 3, 7] → 3

The 7 shows up twice, while the 3 shows up only once.

Example 2
values=[-5, 9, 0, 9, 0] → -5

Both 9 and 0 have a twin; -5 does not.

Example 3
values=[42] → 42
Constraints
  • 1 ≤ len(values) ≤ 3·10⁴
  • -2³¹ ≤ values[i] ≤ 2³¹ - 1
  • Exactly one value appears once; every other value appears exactly twice
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Lost Ticket EasyDoubled Tag, Lost Tag EasyMirror and Negate a Bitmap EasyMultiple of Five at Every Step EasyOrder by Set Bits Easy
loading Python…
Input
values=[7, 3, 7]
Expected
3

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