I have two ordered lists, $l_1$ and $l_2$, each containing $N$ elements ${e_1, e_2, ..., e_N }$ (each only once) in some order.
For each of these elements I calculate their absolute index difference between those two lists and sum them up.
Example with $ N=3 $:
$ l_1 = [e_1, e_2, e_3] $
$ l_2 = [e_2, e_3, e_1] $
$ d_{e_1} = abs(l_1.index(e1) - l_2.index(e1)) = abs(1 - 3) = 2$
$ d_{e_2} = abs(l_1.index(e2) - l_2.index(e2)) = abs(2 - 1) = 1$
$ d_{e_3} = abs(l_1.index(e3) - l_2.index(e3)) = abs(3 - 2) = 1$
$ result = d_{e_1} + d_{e_2} + d_{e_3} = 2 + 1 + 1 = 4 $
What is the maximum possible sum of differences for $N$ elements?
If the two lists have their elements in the same order the sum of differences is the minimum, 0.
The distributions look like this:
It may be that the answer is $ \lfloor N^2/2 \rfloor $, achieved by letting $l_2$ have the reverse order of $l_1$, so there would only be one permutation which has the maximum difference, but I'm not certain