Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Finding the Single Non-Duplicate Element in a Sorted Array: A Binary Search
Mar 22, 2025
320 views
Written by Prashant Basnet
👋 Welcome, You’ve Landed on My Signature Page.
I’m a Software Development Engineer passionate about building scalable systems and solving problems.
Beyond engineering, I enjoy sharing ideas and documenting lessons so others can learn and build on them.This space is my digital notebook, a place where I reflect on what I’m learning and creating.
Situation:
You are given a sorted array of integers where every element appears exactly twice, except for one element that appears only once. Find and return the single element that does not have a duplicate.
Example 2:
Constraints:
Action:
Why Compare Based on Even/Odd Index?
Mid At Even
Mid @ Odd
In a sorted array where every element appears exactly twice except for one, the pairs of duplicates will follow a specific pattern:
This pattern allows us to determine whether the single element is on the left or right side of the middle index.
If mid is even:
Our Strategy:
This can be simplified here: by adjusting mid to always fall on the mid @ even index