On May 13, 1:24 am, amit <amitjaspal...@gmail.com> wrote: > Given an array A[i..j] find out maximum j-i such that A[i]<a[j] in > O(n) time.#include<iostream> using namespace std; #define max 12
int find(int a[],int i,int j) { while(i<j) { if(a[i]<a[j]) return j-i; else if(a[i+1]<a[j]) return j-i-1; else if(a[i]<a[j-1]) return j-i-1; else find(a,i+1,j-1); } if(i>=j) return 0; } int main() { int a[max]={ 18,20,43,2,33,45,32,55,4,33,22,34 }; int l=find(a,0,max-1); cout<<l; return 0; } -- 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.