Find the duplicate element in an array where every element occurs once except one element and every element is between 1 to n without using extra space and in O(n) time complexity
Anonymous
for each element in the array a[i] we can do a[a[i]]*=-1 and at the end, the index which contains a positive integer will be the result as it is the only element that is multiplied twice by -1.
Check out your Company Bowl for anonymous work chats.