C++20 sections · 1024 units
Open in Course

Problem - Presents

Tracking gift exchanges

You have nn friends numbered 11 to nn. Each friend gave a present to exactly one other friend. You're given an array where position ii tells you who friend ii gave their present to.

Your task: figure out who gave a present to each friend. This problem teaches you array index manipulation. You'll work with two arrays: one showing who each person gave to, and another showing who gave to each person.

The challenge is reversing the relationship using array indices. Before moving forward, think about this: if friend 33 gave to friend 77, what should position 77 in your answer array contain? That question reveals the solution.