hi hw about this
for(i=0;i<n;++i)
{
if(a[a[i]]!=a[i]&&flag==0)
{
a[a[i]]=a[i];
flag=1;
}
else
{
cout<<a[i] "is duplicate element";
}
}
if range is high we hash take mod of that elemnt with big value and hash it
in same array and check for collision
On Mon, Oct 5, 2009 at 10:09 AM, Amit Chandak <[email protected]>wrote:
>
> Hi Friends,
> Given an array in which all the elements are unique except one element
> which occurs 'twice'. How can we find this repeated element in O(n)
> time and constant space?
>
> Regards,
> Amit.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---