Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

67. Single Element in a Sorted Array

MediumDay 19 of 60Binary Search

You are given a sorted array in which every value appears exactly twice, except for one value that appears only once. Return that single value. Your solution must run in O(log n) time and O(1) extra space.

Example 1
Input: nums = [1,1,2,3,3,4,4,8,8]
Output: 2
Example 2
Input: nums = [3,3,7,7,10,11,11]
Output: 10
Constraints
  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^5
  • `nums` is sorted and has odd length
Hints
Frequently asked at: Google, Amazon, Meta
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min