For the sample input [ 55, -8, 43, 52, 8, 59, -91, -79, -18, -94 ] the expected value = 158. But I believe the answer should be 157.

I used Ruby to solve this problem and I keep getting 157 for the output, and it makes sense when I use the formula for f(i, j).

For the inputs above, the max value is 59 and index 5, and the min value is -94 at index 9.

The formula we are given is f(i,j) = |A[i] - A[j] | + |[i - j]|

When plugging in the values above for the formula we get:

f(5, 9) = |A[5] - A[9]| + |5 - 9|

= |59 - (-94)| + |-4|

= 153 + 4 = 157

What am I doing wrong that is giving me an off by 1 error?