@juver:thanx for making me work... please notice this
this also uses the sorted property of the array
i=0,j=1;
while((i!=n-1) or j!=n)
{
/*compare difference of a[j] and a[i]*/
if( (a[j]-[a[i]])>x )
i++;
else if( (a[j]-a[i])<x)
j++;
else
{
/*SOLUTION*/
return;
}
}
regards
complexity:O(n)
On Thu, Dec 23, 2010 at 12:29 AM, juver++ <[email protected]> wrote:
> Your solution needs extra space and it has only *expected* O(n) time.
> There is O(n) inplace solution
>
> --
> 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]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
bhupendra dubey
--
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?hl=en.