Given a list of strings lst and a list of integers p, reorder lst so that every lst[i] gets placed to p[i]. Example 1 Input
lst = ["a", "b", "c", "d"] p = [3, 0, 1, 2] Output
["b", "c", "d", "a"] Explanation
a goes to index 3 b goes to index 0 c goes to index 1 d goes to index 2
I am trying to solve this by decomposing permutation p into a product of transposition(swaps) and then use those swaps to reorder lst.. can anyone give me the code for decomposing a permutation into a product of transpositions? Note it has to be done in O(1) space..otherwise it is trivial