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
395 views
Written by Prashant Basnet
👋 Welcome to my Signature, a space between logic and curiosity.
I’m a Software Development Engineer who loves turning ideas into systems that work beautifully.
This space captures the process: the bugs, breakthroughs, and “aha” moments that keep me building.
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