C++20 sections · 1024 units
Open in Course

Presents - The Idea

Inverting the mapping

The insight: you need to reverse the direction of the relationship. The input tells you "person ii gave to person If friend ii gave to friend This pattern shows up in many problems.

When you have a mapping from AA to BB, and you need the reverse mapping from BB to AA, use the value as an index. This is a core array manipulation technique. This insight transforms a complex-looking problem into a manageable one.

Without it, you might overcomplicate the solution or miss edge cases. Look for this pattern in similar problems. Recognizing it quickly will help you solve problems faster in contests and interviews.