The problem gives you a permutation where friend[i] = j means "friend i received gift from friend j". You need to find the inverse: who did each friend give their gift to?
Create an output array of size n.
For each i from 1 to n, you know friend i received from friend[i]. This means friend[i] gave to friend i.
So set output[friend[i]] = i.
After processing all entries, output contains the answer. Print it. The trick is that "i received from j" is equivalent to "j gave to i". You're reversing the direction of the relationship.