For integer array A, return the maximum possible total distance between the two elements. The total distance is defined as A[i] + A[j] + (i - j) for i> j
For example, with A = [8, 2, 4, 9, 5, 8, 0, 3, 8, 2] maximum total distance is 24 for i = 0 and j = 8
The solution O ( n 2 ) is trivial. Is there an O ( n ) solution (where n is the length of the array)?
algorithm
marian.biter
source share