Here's the solution using array index manipulation: function solvePresents(n, p) answer := array of size n + 1 // 1-indexed for i from 1 to n recipient := p[i] answer[recipient] := i for i from 1 to n print answer[i] return You loop through the input array once, using each value as an index to fill the answer array.
The statement Pay attention to data types and loop bounds. Off-by-one errors are common. Test with sample inputs before submitting. If something fails, add print statements to trace variable values.
Debugging is easier when you can see what your code computes.