Given a list of pairs, find the orientation they should be placed in a line, such that the sum of the absolute values of the differences is zero.
Zero means do not invert, One means invert in the order vector.
list = [1 2
4 2
2 3
order = [0 1 1]
yields: [1 2][2 4][3 2]
or: abs(2-2) + abs(4-3)
or: 0 + 1
or: 1
There is a unique solution to this problem where the final score is minimized.
Solution Stats
Problem Comments
5 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers276
Suggested Problems
-
Find state names that end with the letter A
1197 Solvers
-
Arrange vector in ascending order
814 Solvers
-
Matrix which contains the values of an other matrix A at the given locations.
239 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
13591 Solvers
-
Convert from Fahrenheit to Celsius
27607 Solvers
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!
No unique solution. For me it is the last solution of the permutation matrix.
For which test statement is there not a unique solution? We need to fix the test suite if there are two answers of same score.
Sorry, it was a mistake.
The statement of the problem is incorrect: "the sum of the absolute values of the differences is zero." You want the smallest sum, but it isn't necessarily zero.
Is there any size constraint on this problem ? My solution is not getting accepted ...