i ve asked the same question 6 months ago but havent really understood how to solve this yet

suppose that we have an array of size n where n <=10 and the keys are 1,2,3

if n = 3 then

Code:
A[] = {2,1,3}
we want to find the min cost in order to sort it in an ascending order

one way would be the following

Code:
2 1 3
2 3 1
1 3 2
1 2 3
with a total cost of 3

another way would be the following

Code:
2 1 3
1 2 3
with a total cost of 1

but if we have a bigger number of n for example n = 5 the problem gets harder

Code:
A[] = {3,2,2,1,3}
etc

i ve tried many sorting algorithms, one that suits the problem is counting sort, but that hasnt helped me at all

can anyone please help me with hints? thanks