@atul...

For the O(n^2) approach, here's the working code..It should work for
all ur examples.. I have fixed it..

int max = 0;
int strtind = -1;
int endind =  -1;

int X[2][N];

for(int i=0;i<=N;i++)
   X[0][i]=X[1][i] = 0;

int *prev, *curr;
for (int i = 0; i < N; ++i)
{
  prev = X[i%2];
  curr = X[(i+1)%2];

  for (int j = 0; j < N; ++j)
  {
       curr[j+1] =  ( abs(A[i] - A[j]) > K ) ? 0 : 1 + min(curr[j],
min(prev[j+1], prev[j]));
       if ( curr[j+1] > max)
       {
            max = curr[j+1];
            strtind = j - max + 1;
            endind = j;
        }
  }
}
printf("%d , %d, %d", max, strtind, endind);


Let me know if u hit an issue...
-------------------------------------------------------------------------------

For the heap approach it seems that it worked for u..as i see that in
the last post u have corrected the storage of values to indices..
Am i ryt? Did it work for u?
In case u have a doubt, plz let me know...

-----------------------------------


On Jan 3, 4:01 pm, atul anand <[email protected]> wrote:
> @above : correction...
>
> while(MaxH is not empty)
> {
>       if (Top(MaxH) < currentStrInd)    // *4(index of 9) < 2 *    ->move
> to else if condition
>         pop(Top(MaxH)) ;
>
>      else if (A[Top(MaxH)] - A[Top(MinH)] <= K)  --> *9-1 <= 8* TRUE
> .....break this loop.
>         break;
>
>
>
>
>
>
>
> }

-- 
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.

Reply via email to