Minimum of sum of absolute values

Viewed 4101

Problem statement:

There are 3 arrays A,B,C all filled with positive integers, and all the three arrays are of the same size.

Find min(|a-b|+|b-c|+|c-a|) where a is in A, b is in B, c is in C.


I worked on the problem the whole weekend. A friend told me that it can be done in linear time. I don't see how that could be possible.

How would you do it ?

2 Answers
Related