Solution algorithm is wrong for (1,2,2,1)


#1

The result of solution apgorithm is (1,1,2,2) that is wrong.


#2

Read the problem statement carefully. (1, 1, 2, 2) indeed satisfies the criteria and is also the lexicographically smallest.