Find the Duplicate Number
Practice this coding question on Coding Gurukul.
Problem statement
A locker scan produces n + 1 labels, each between 1 and n. Exactly one distinct label is repeated, possibly more than twice; all other labels appear at most once. Identify the repeated label without modifying the scan and using constant extra space.
Input format
First line: n. Second line: n + 1 integers.
Output format
Print the repeated label.
Constraints
1 <= n <= 100000; 1 <= label <= n; exactly one distinct repeated label.
Sample input
5 4 2 5 1 3 2
Sample output
2
Sign in to run or submit a solution in C++, Java or Python.