@kunal.... i think we both understood the problem differently...thats what i asked from amit..that whether in the window is it neccessary the elements in between should also be in increasing order or only the end elements should have the relation of one being greater than the other...I too thought for the same kind of algo had it been the first case...but i think its the second case amit is asking for....and if it is so..ur answer is wrong...it should be 6(j-i=6-0=6)
On 5/17/11, Kunal Patil <[email protected]> wrote: > @Anuj & Piyush: > You didn't get the algo. It works on unsorted array also. You might have > missed the statement > *"else // next element is smaller than or equal to current element > reset curr_max to 1;*" > Here, the comment itself shows unsorted elements have been taken into > consideration. > If you still have the doubt let me know. > Here is code for you: > > #include<cstdio>#define MAX_SIZE 10 > int maxinterval(int a[],int size){ > int curr_max=1, prev_max=1; > > for(int k=0;k<size-1;k++) > { > if(a[k] < a[k+1]) > { > curr_max++; > > if(curr_max > prev_max) > { > prev_max=curr_max; > } > } > else > curr_max=1; > } > return prev_max;} > int main(){ > int arr[MAX_SIZE] = {19,18,17,21,22,23,24}; > printf("%d\n",maxinterval(arr,7) ); > getchar();} > > As expected it gives output 5. > > -- > 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. > > -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=100000655377926 * -- 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.
