Given a graph of friends who have different interests, determine which groups of friends have the most interests in common. Then use a little math to determine a value to return.
The graph will be represented as a series of nodes numbered consecutively from 1
to friends_nodes
. Friendships have evolved based on interests which will be represented as weights in the graph. Any members who share the same interest are said to be connected by that interest. Once the node pairs with the maximum number of shared interests are determined, multiply the friends_nodes
of the resulting node pairs and return the maximal product.
Function Description
Complete the function maxShared
in the editor.
maxShared
has the following parameter(s):
int friends_nodes
: number of nodesint friends_from[friends_edges]
: the first part of node pairsint friends_to[friends_edges]
: the other part of node pairsint friends_weight[friends_edges]
: the interests of node pairsReturns
int
: maximal integer product of all node pairs sharing the most interests.
Example 1:
Input: friends_nodes = 4, friends_from = [1, 1, 2, 2, 2], friends_to = [2, 2, 3, 3, 4], friends_weight = [2, 3, 1, 3, 4]
Output: 6
Explanation:- Node pair (2,4) shares only 1 interest (4) and node pair (1,3) shares 1 interest (3). - Node pair (1,2) shares 2 interests (interests 2 and 3) and node pair (2, 3) shares also 2 interests (interest 1 and 3). So, the maximum number of shared interests is 2. - Multiply the
friends_nodes
of the resulting node pairs: 1 × 2 = 2 and 2 × 3 = 6. - The maximal product is 6.
A yet-to-be-unearthed secret 🫢

input:
output: