Suppose that I have an array of random reals, how do I the indices pair (i, j)
where j<i
and
maximise (a[j] - a[i])
in O(n ln(n))
time
n ln n sugguest recursions. So I was thinking of sorting the array in n ln n sort. but then the min and mix of the sorted array might not satisfy j<i
The difference a[j]-a[i]
depends on all i , j so scanning all the possible permutation is O(n^2)
. Does anybody have a suggestion on how I can divide the problem space?