Question is:

Calculate the minimum absolute difference between the maximum and minimum number from the triplet a, b, c such that a, b, c belongs arrays A, B, C respectively.

There is another question: Find i, j, k such that : max(abs(A[i] - B[j]), abs(B[j] - C[k]), abs(C[k] - A[i])) is minimized. Return the minimum max(abs(A[i] - B[j]), abs(B[j] - C[k]), abs(C[k] - A[i])). A, B & C are sorted arrays.

Reading the solution approach here and here, I realize that the solution approach for both these questions is same, to:

minimize abs( max(a,b,c) - min(a,b,c) )

I'm not sure why this follows and how we should go about relating these two questions and their algorithms. Why are these two questions identical?


Can you see the following equality?
abs( max(a,b,c) - min(a,b,c) ) = max(abs(a - b), abs(b - c), abs(c - a))

Here is a hint to prove the equality.

Without loss of generality, we can assume a >= b >= c.

By the way, the first abs is not necessary since max(a, b, c) is always no less than min (a, b, c).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.