Checkout your overall progress in every topic here
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
Avg time to solve 15 mins
Success Rate 85 %
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.
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 )
The first line of input contains an integer ‘T’ denoting the number of test cases. Then the T test cases follow.
The first line of each test case contains an integer ‘N’, the number of elements in the array.
The second line of each test case contains ‘N’ space-separated integers representing the elements of the array.
For each test case, the duplicate element of the given array is printed.
The output of each test case is printed in a separate line.
You are not supposed to print anything; It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10^5
1 <= ARR[i] <= N - 1
Time Limit: 1 sec
Sample Input 1:
1 1 2
Sample Output 1:
Explanation of Sample Input 1:
1 is repeated in the array, hence function returns 1.