How to find a duplicate element in an array