Single Element in Sorted Array Problem
Single Element in Sorted Array Problem — ExecCode Easy DSA Practice
Solve the Single Element in Sorted Array problem on ExecCode. Free online easy DSA practice in Arrays / Binary Search. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Your task is to compute the required answer and return the single element that appears only once. Your solution must run in O(log n) time and O(1) space.
Examples
Input {"nums": [1, 1, 2, 3, 3, 4, 4]}; Output 2. Input {"nums": [1, 1, 2, 2, 3]}; Output 3. Input {"nums": [1, 1, 2, 2, 3, 3, 4, 8, 8]}; Output 4
Constraints
1 <= nums.length <= 10^5 0 <= nums[i] <= 10^5
Practice Single Element in Sorted Array free on ExecCode. Browse DSA problems, topic map, and placement guides.