Problme is not clear.
Quesrtions:
1. Is the array all of positive numbers
if yes then sort the array in ascending order. Now for every j, j>i
and i,j <=n, A[j]>A[i] and so A[j]-A[i] > 0. Now if we want max(j-i)
such that A[j]-A[i]>0, it has to be j=n, the last element of A and
i=1, the first element of A
Time Complexity = O(nlogn) for sorting.

2. Is array consisting of +ve and -ve numbers?
Again sort in ascending order(nlogn). We know A[j] is max of all
elements. If A[j] <= 0, then no solution exists. Else if A[j] +ve then
again j=n, the last element of A and i=0 the first element is answer.

Sourav Sain


On Jun 12, 12:14 am, amit <[email protected]> wrote:
> given an array A of n elements.
> for indexes j , i such that j>i
> maximize( j - i )
> such that A[j] - A [ i ]> 0 .
>
> Any Algorithm less than O(n^2) would do.

-- 
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.

Reply via email to