Write a function
that returns
| ⎧ ⎨ ⎩ | min(V[i], V[j]) × (j − i) | ⎫ ⎬ ⎭ | . |
For instance, the answer for [9, 7, 4, 1] is 8, corresponding to the numbers 9 and 4, which are at distance 2. As another example, the answer for a vector with eleven 109 is 1010.
Precondition
V has between 2 and 105 numbers, all between 0 and 109.
Observation
The expected solution has cost Θ(V.size()), with a small constant.
Observation You only need to submit the required procedure; your main program will be ignored.