You are given a permutation of N numbers from 1 to N in an array
You want to sort the array using this operation
- Send the front-most element X places back in the array;
- Add x to the total cost.
N<=10^5
Input : A = { 1 , 3 , 2 }
output : 3.
Explanation :
=> Send 1 to index 1. (Cost +1)
A [3, 1, 2]
Send 3 to index 2. (Cost +2)
A = [1, 2, 3]
and the array is sorted.
hence total cost = 3.
Any approach for solving this problem>