@atul.. No need to remove continue.. 'continue' has been added for optimization..
(max - min) > K, should only be checked when either we get a new min or max... In case the current processed element is neither a good fit for max or min then we need not check for the difference.. On Jan 1, 2:33 am, atul anand <[email protected]> wrote: > start=0; > > maxLen=0; > min=arr[0]; > max=arr[0]; > j=0; > > for(i=1;i<n;i++) > { > if(arr[i] > max) > max=arr[i]; > else if(arr[i] < min) > min=arr[i]; > > if( (max - min ) > k && maxLen < ( i - j ) ) > { > maxLen=i - j; > start=j; > end=i-1; > > } > else > { > next=i; > max=min=arr[next]; > for(k=j;k<next;k++) > { > if(abs(arr[next] - arr[ j]) < k) > { > if(arr[k] > max) > max=arr[k]; > else if(arr[k] < min) > min=arr[k]; > > if(index == -1) > { > flag=1; > index=k; > } > > } > else > { > flag=0; > index=-1; > } > > } > > if(flag==1) > { > j=index; > i=index-1; > } > else > { > j=i; > max=arr[i]; > min=arr[i] > i--; > } > }//end else > > > > > > > > } -- 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.
