Connection Status:
Competition Arena > SocialNetwork
TCO18 Poland · 2018-04-20 · by misof · Brute Force, Simple Search, Iteration, String Manipulation
Class Name: SocialNetwork
Return Type: double
Method Name: averageFriends
Arg Types: (vector<string>)
Problem Statement

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 String[] interests. Each element represents the interests of a single member: each character ('A'-'Z') represents a different interest. Two individuals become friends if they have at least one interest in common. Return the average number of friends each member has.

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.
Examples
0)
{"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.

1)
{"ABC", "DE", "FGHIJ"}
Returns: 0.0

Three people with no common interests.

2)
{"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.

3)
{"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.

4)
{"ABCDE", "BCDEF"}
Returns: 1.0

Even if people share multiple common interests, they are only friends once.

5)
{"", "", "", ""}
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.

Coding Area

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

Submitting as anonymous