I came across a post How to find a duplicate element in an array of shuffled consecutive integers? but later realized that this fails for many input.
For ex: a
a
Although the answers provided here are good, yet I'd like you to refer the answer by Mohit Jain if there is an ambiguity.
The fact variable xor variable = zero can be used to locate the duplicates present in the array precisely and easily. Hope that helps!
variable xor variable = zero