As reported: Synopsys R&D Engineer Sr, round 2 (2024): single element in a sorted array.
You are given a sorted array in which every element appears exactly twice, except one element that appears once. Return the single element. Your solution must run in O(log n) time and O(1) space.
This is LeetCode 540 — Single Element in a Sorted Array.
Example 1
nums = [1,1,2,3,3,4,4,8,8] -> 2
Example 2
nums = [3,3,7,7,10,11,11] -> 10
Constraints: 1 ≤ nums.length ≤ 10^5 (always odd); 0 ≤ nums[i] ≤ 10^5.
Code runner format: one line: nums as a JSON array. Implement singleNonDuplicate(nums); the harness prints the returned number.