Description
Solutions
Submission
Shared Interest 🌷
🔥 FULLTIME

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 nodes
  • int friends_from[friends_edges]: the first part of node pairs
  • int friends_to[friends_edges]: the other part of node pairs
  • int friends_weight[friends_edges]: the interests of node pairs
  • Returns

    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.
    Constraints:
      A yet-to-be-unearthed secret 🫢
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: