easyBit ManipulationPure DSA~12 min
Lone Sensor Reading
Every sensor in a redundant rack reports its reading twice for fault tolerance — except one sensor whose duplicate packet was dropped. Given all received readings, identify the single un-paired reading using constant memory.
Problem
Given an array where every value appears exactly twice except for one value that appears once, return the single value.
Input
An array nums of length n (n odd, 1 ≤ n ≤ 10^5), values in [0, 10^9].
Output
A single integer — the value that appears once.
Constraints
- n is odd; exactly one value is un-paired
- Every other value appears exactly twice
- Use O(1) extra space
Examples
Example 1
Input
nums = [4, 1, 2, 1, 2]
Output
4
1 and 2 each appear twice; 4 is the lone reading.
Example 2
Input
nums = [7]
Output
7
A single reading is trivially un-paired.