Problem Statement -
The task is to find the minimum number of swaps required in the given arrangement of cartons to get the desired arrangement of cartons. Only adjacent cartons can be swapped.
I have tried an ad hoc approach, but it proved inefficient towards the upper limit of the data range. Here it is for reference -
Traversing through the given arrangement of cartons
if position of carton>than the desired position
swap back
go to previous iteration
What would be a pragmatic approach to the problem?
Test Data Range - N<=105
Source - INOI 2009 Q Paper