SocialNetwork
TCO18 Poland · 2018-04-20 · by misof
Problem Statement
A new social network automatically matches people together based upon a shared interest. A list of interests for each member of the social network is given in the
Notes
- Your return value must have an absolute or a relative error at most 10^(-9).
Constraints
- interests will contain between 2 and 50 elements, inclusive.
- Each character in each element of interests will be an uppercase English letter ('A'-'Z').
- The characters in each element of interests will be distinct.
{"A", "A"}
Returns: 1.0
Two people who share a common interest. Thus, they each have one friend, and the average number of friends is therefore also 1.
{"ABC", "DE", "FGHIJ"}
Returns: 0.0
Three people with no common interests.
{"ABC", "DE", "FGHIJA"}
Returns: 0.6666666666666666
This is almost the same situation as Example #1 but now two of the people share a common interests. Now these three people have 1, 0, and 1 friends, respectively. The average number of friends is (1+0+1)/3 = 2/3 = 0.6666666667.
{"AB", "AC", "AD", "AE", "BCDE"}
Returns: 4.0
All of these people are friends with each other, even though there is no single topic they would all be interested in.
{"ABCDE", "BCDEF"}
Returns: 1.0
Even if people share multiple common interests, they are only friends once.
{"", "", "", ""}
Returns: 0.0
Four grumpy people who are not interested in anything.
Submissions are judged against all 9 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SocialNetwork with a public method double averageFriends(vector<string> interests) · 9 test cases · 2 s / 256 MB per case