JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat  | Threaded  | Tree
Previous Thread  |  Next Thread
Example 3 | Reply
Please refer to the example 3 having following code:

int j=0;
for (int i=0; i<N; i++) {
while ( (j><N-1) && (A[i]-A[j] > D) )
j++;
if (A[i]-A[j] == D) return 1;
}

This would fail if the input integer array has following values and D =1 :

10, 5, 4, 2

I feel there is a problem with the way j is incremented.

Am i missing something??

Thanks
Subject Author Date
Example 3 jchaganti Apr 8, 2007 at 8:06 AM EDT
Re: Example 3 misof Apr 8, 2007 at 3:05 PM EDT
Re: Example 3 bharadwaj6 Dec 16, 2013 at 6:03 AM EST
RSS