Given a list of ordered pairs, find the order they should be placed in a line, such that the sum of the absolute values of the differences is minimized.

list = [1 2
        5 3
        2 4
order = [1 3 2]
yields: [1 2][2 4][5 3]
    or: abs(2-2) + abs(4-5)
    or:        0 + 1
    or: 1

There is a unique best solution, but the score is NOT always zero.

Solution Stats

715 Solutions

346 Solvers

Last Solution submitted on Mar 10, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers346

Suggested Problems

More from this Author51

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!