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

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

one way would be the following

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

another way would be the following

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

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

etcCode:A[] = {3,2,2,1,3}

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