// The result will always include the smallest value of A[i] where i is 
less than j,
// so just keep track of that minimum value as you scan through the array.

int findPair(int *A, int N)
{   
   min = A[0];   
   max = 0;
   for(j = 1; j < N; ++j)
   {
      if ((A[j] - min) > max) max = A[j] - min;
      if (A[j] < min) A[j] = min;
   }

   return max;
}

On Friday, April 18, 2014 4:49:26 PM UTC-4, TUSHAR wrote:
>
> Hi All,
>
> Can anyone help me solving this problem ?
>
> Given a non-empty array A consisting of N integers.
>
> Find Max(j-i), s.t 0<=i<=j<N  and A[i]<=A[j]
>
> Here (i, j) is a Monotonic Pair, satisfying the above condition.
>
> Space Complexity : O(n)  Time Complexity: O(n)
>
> -- 
> Regards...
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].

Reply via email to