[algogeeks] Finding a single repeated element in an array

2007-08-16 Thread dsha
Hi there, I'm interested in the following problem: there is an array of integers that contains each element only once except for one element that occurs exactly twice. Is there a way to find this element faster than O(n*log n) and with constant extra memory? If no, how can I prove it? Thanks in

[algogeeks] Re: Finding a single repeated element in an array

2007-08-16 Thread Vaibhav Jain
if u know the range of values stored in array then let me assume values 1 to k then u can calculate sum of numbers stored in array in O(n) complexity. after that apply formula duplicate value= [k*(k+1)]/2 - sum of numbers stored in array it will take O(1) constant time so total complexity