- two pointers
- maximum cardinality matching
To solve this problem one needs to overcome two challenges. First, how to efficiently construct a graph representing the shared characteristics between people. Second, how to use such a graph to check whether there is a better choice of buddies than the provided baseline.
We begin by reading the characteristics of each vertex into a vector and sorting it.
Then, for each pair of vertices, we iterate through their (sorted) lists of characteristics once using two pointers to count the number of shared characteristics.
This can be done in
We subtract
This step can be done in