The question states - For an array, find the maximum value of (j-i)*min(a[j], a[i]), where i and j are distinct indices of the array in the range {0,1, .., n-1} where n is the array length.
I went with an ill-thought-out solution where I have 2 pointers at both ends of the array and reject the one with a smaller array value. But it is still working. How?
i, j = 0, n-1
ansSoFar = 0
while i <= j:
ansSoFar = max(ansSoFar, (j-i)*min(A[i], A[j]))
if A[i] > A[j]:
j -= 1
else:
i += 1
return ansSoFar