Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Find The Single Element
EASY
Binary Search
Arrays
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Binary Search
-
-
Arrays
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Find The Single Element

Contributed by
Shivam Ruhil
Easy
yellow-spark
0/40
Share
0 upvotes

Problem Statement

You are given a sorted array ‘Arr’ of positive integers of size ‘N’, which contains each number exactly twice except for one number, which occurs exactly once. You have to find the number that occurs exactly once.

For Example:

For ‘N’ = 7 and ‘Arr’ = {1, 1, 2, 3, 3, 4, 4}.
1, 3, and 4 occur exactly twice. 2 occurs exactly once.  
Hence the answer is 2.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
5
1 1 2 2 3
Sample Output 1:
3
Explanation of sample output 1:
{1, 2} each occurs twice, whereas, 3 occurs only once.
Hence the answer is 3.
Sample Input 2:
5
8 8 9 9 10
Sample Output 2:
10
Reset Code
Full screen
Auto
copy-code
Console