ok ...
@Lucifier i have optimized your code further so that there is no need to
check every element i.e to outer for loop..
so i have skipped elements if they can never be part of second maxLen
sequence if exits.

int find_seq(int arr[],int *start,int *end,int k,int n)
{
int maxLen=0;
int min=arr[0];
int max=arr[0];
int i,j=0,next,index=-1,p,flag=0;

for(i=1;i<n;i++)
{
       flag=0;
       if(arr[i] > max)
       max=arr[i];
       else if(arr[i] < min)
       min=arr[i];
       else
continue;

       if((max - min ) > k)
       {
    flag=1;
       }
       if(flag==1)
       {
     if(maxLen < ( i - j))
     {
maxLen=i - j;
*start=j;
*end=i-1;

     }
     index=-1;
     next=i;
     for(p=j;p<next;p++)
     {

if((abs(arr[next] - arr[p])) <= k)
{
if(index==-1)
{
i=p-1;
j=i+1;
index=1;
}

}
else
{
index=-1;
i=p;
j=i+1;
}


     }
     max=arr[j];
     min=arr[j];

       }
}

if(maxLen < ( i - j ))
{
   maxLen=i - j;
    *start=j;
    *end=i-1;
}
return 1;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to