Problem 333276 · medium · Level 03 Linear Management & Searching

The Unpaired Value

binary search · parity

In the sorted list nums every value appears exactly twice, except for one value that appears exactly once. Return that value.

Examples

Input:  nums = [3, 3, 6, 6, 8, 11, 11]
Output: 8

Input:  nums = [1, 1, 2, 2, 3]
Output: 3

Input:  nums = [0, 1, 1]
Output: 0

Constraints

  • len(nums) is odd and 1 <= len(nums) <= 10**6
  • Aim for O(log n) time. (A full scan or a Counter still passes the tests; the point is to find the value without one.)

Goals

  • Use index parity to tell which side of the array contains the odd one out
  • Keep the search space aligned to pairs
Starting Python…