The input consists of natural number N and M (N <= 2*10^5 and M < N). \n↵
Then you are given a permutation of numbers [1, N] \n↵
You should sort the given array, but only the following operation is allowed: \n↵
Chose a number with index from [0, M-1] and choose a number from [M, N-1], then swap then. \n↵
What is the minimum number of operations to sort the array? \n↵
Example: \n↵
5 3 \n↵
1 2 3 5 4↵
--------- \n↵
1 2 5 3 4 (swap 3 and 5) \n↵
1 2 4 3 5 (swap 4 and 5) \n↵
[1 2 3 4 5] (swap 3 and 4, now the array is sorted, total steps = 3)↵
\n↵
\n↵
Any idea on how to solve this problem?
Then you are given a permutation of numbers [1, N] \n↵
You should sort the given array, but only the following operation is allowed: \n↵
Chose a number with index from [0, M-1] and choose a number from [M, N-1], then swap then. \n↵
What is the minimum number of operations to sort the array? \n↵
Example: \n↵
5 3 \n↵
1 2 3 5 4
---------
1 2 5 3 4 (swap 3 and 5) \n↵
1 2 4 3 5 (swap 4 and 5) \n↵
[1 2 3 4 5] (swap 3 and 4, now the array is sorted, total steps = 3)
\n↵
Any idea on how to solve this problem?