Given an array A = [a1, a2, ..., an] and another array B, where B is some permutation of the numbers 1, 2, ... n, how can I order the elements of A according to the permutation B in-place (so you cannot make an extra array)?
For example, if A = [27, 15, 11, 19] and B = [3, 2, 4, 1], then we would have to modify A to get [19, 15, 27, 1].
This problem seems really easy at first, but I thought it was quite difficult with the memory constraint. I wasn't able to solve this problem, but I was wondering whether someone else would be able to show me how to solve it.