540. Single Element in a Sorted Array
Intuition
In a sorted array where every element appears exactly twice except one, the pairs are positioned such that:
Before the single element, the first instance of a pair appears at even indices.
After the single element, the first instance of a pair appears at odd indices.
By checking index parity and using binary search, we can determine which side the single element lies on and reduce our search space efficiently.
Complexity
Space Complexity
Time Complexity
Code
Last updated