I'm sorry that I'm not sure what type is this problem called, let's just call it "Remapping", described as follows: Given a target char array, say A[], you have to manipulate A directly. And a remapping index array index[] containing indices where the value should be re-assigned. For example, given A[] = {a, b, c, d, e}, index[] = {2,4,3,0,1}. So index[0] = 2, which means after the manipulation, the value once in A[0] has to be A[2], A[1] is at A[4], etc. I know this problem is extremely easy if we have another array:
vector<char> myarr = vector<char>(A.size());
for (int i = 0; i < myarr.size(); i++)
myarr[i] = A[index[i]];
// myarr is the answer.
But what should I do if I am only allowed O(1) space ? Thanks for sharing your opinion.
Oh btw, correct me if I have any grammar errors :"P