C++20 sections · 1024 units
Open in Course

Team Uniforms - The Idea

Polymorphism benefits

Define a base Team class with virtual methods getHomeColor() and getAwayColor(). The comparison logic uses these methods without knowing the concrete team type.

Virtual methods enable runtime polymorphism. When you call team->getHomeColor() through a base pointer, the actual derived class's method runs. This means you can add new team types later without changing the comparison code.

For this problem in particular: loop through all pairs (i,j)(i, j) where iji \neq j. When ii hosts, check if teams[i].homeColor equals teams[j].awayColor. Count all matches. The nested loop gives you O(n2)O(n^2) comparisons.