Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Find Duplicate in Array
EASY
15 mins
716 upvotes
Sorting
Binary Search
Arrays
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Sorting
-
-
Binary Search
-
-
Arrays
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
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 Duplicate in Array

Contributed by
Dhruv Sharma
Easy
yellow-spark
0/40
Avg time to solve 15 mins
Success Rate 85 %
Share
716 upvotes

Problem Statement

You are given an array of integers 'ARR' containing N elements. Each integer is in the range [1, N-1], with exactly one element repeated in the array.

Your task is to find the duplicate element. The duplicate element may be repeated more than twice in the error, but there will be exactly one element that is repeated in the array.

Note :

All the integers in the array appear only once except for precisely one integer which appears two or more times.
Detailed explanation ( Input/output format, Notes, Constraints, Images )

Sample Input 1:

1
3
1 1 2

Sample Output 1:

1

Explanation of Sample Input 1:

1 is repeated in the array, hence function returns 1.

Sample Input 2:

3
5
1 3 4 2 2
5
3 1 3 4 2
3
1 1 1

Sample Output 2:

2
3
1
Reset Code
Full screen
Auto
copy-code
Console