This problem teaches you inverse permutation. When you have a mapping showing where each element goes, you can reverse it by using values as indices.
Array indices are bidirectional. You can use position to find value, or use value to determine position. The statement answer[p[i]] = i shows this power.