Given an array arr = {5, 16, 4, 7}
, we can sort it through sort(arr, arr+sizeof(arr)/sizeof(arr[0]))
.
so now the array arr = {4, 5, 7, 16}
and the permutation index for the sorted array is {2, 0, 3, 1}
.
In other words, the arr[2]
in the original array is now the smallest element in the sorted array in position 0
.
Is there an efficient way so that we can get the permutation index?
Thank you
See Question&Answers more detail:os