find out the max distance between a[i] and a[j] such that a[i] < a[j]
and i < j. Time complexity is O(n).