Single Element in a Sorted Array

Let's try to use a sorted array with duplicates as the input array. Difficulty Level: Medium

Problem statement

Suppose we are given a sorted array that only consists of integers, where every element appears twice, except for one element which appears once. Find the element that appears only once.


  • 1nums.length1031 \leq nums.length \leq 10^3
  • 0nums[i]1030 \leq nums[i] \leq 10^3

Example 1:

Input: [1,1,2,3,3,4,4,8,8]    
Output: 2

Example 2:

Input: [3,3,7,7,10,11,11]    
Output: 10

Example 3:

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

Example 4:

Input: [1]    
Output: 1

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.