C++20 sections · 1024 units
Open in Course

Games - Implementation

Complete solution

class Team
 homeColor, guestColor
 
 constructor(home, guest)
 this.homeColor := home
 this.guestColor := guest

function count_conflicts(teams)
 conflicts := 0
 n := length of teams
 for i from 0 to n - 1
 for j from 0 to n - 1
 if i  j then
 if teams[i].homeColor = teams[j].guestColor then
 conflicts := conflicts + 1
 return conflicts
``` homeColor with teams[j].guestColor. The time complexity is $O(n^2)$ where $n$ is the number of teams.