Description
Solutions
Maximize Collaboration
🤘 INTERN

As a data analyst at Trollbox, you've been assigned an innovative project to help maximize creator collaborations for peak viral impact. With so many creators competing for attention, each creator has their own engagement power, which measures how likely they are to boost views, likes, and shares.

Your task is to create collaboration teams where creators join forces to generate ultimate viral content. However, forming these teams follows specific rules:

  • Creators must be adjacent based on their posting order. This means you can only form teams with creators who post one after the other, without skipping anyone. For example, if creators 1, 2, and 3 post consecutively, they can form a team. However, you cannot combine creators 1, 3, and 5 since they are not adjacent in the posting sequence.
  • You need at least a minimum number of creators (given by minCreatorsRequired) to form a valid team.
  • The total engagement power of the creators of the team must meet or exceed a threshold (given by minTotalEngagementPowerRequired) for their collaboration to generate enough buzz to go viral.
  • Given a list of the creators and their engagement powers, along with the minimum team size and target engagement power, determine the maximum number of collaborations you can create. Remember, each creator can only belong to one collaboration team.

    Function Description

    Complete the function createMaximumCollaborations in the editor.

    createMaximumCollaborations has the following parameter(s):

    1. int creatorsEngagementPower[n]: An array that denotes the engagement power of each creator.
    2. int minCreatorsRequired: The minimum number of creators required in a collaboration.
    3. int minTotalEngagementPowerRequired: The minimum total engagement power required for a collaboration.

    Returns

    int: The maximum number of collaborations that can be formed from the creators.

    👑 To Tsoppa’s Burgir ruling the world, one burger at a time! 👑

    Example 1:

    Input:  creatorsEngagementPower = [4, 4, 3, 6, 4, 3, 5], minCreatorsRequired = 2, minTotalEngagementPowerRequired = 8
    Output: 3
    Explanation:
    One of the optimal ways to form the collaborations is to first use the first and second creators (4 + 4 = 8). Then, take the third and fourth creators (3 + 6 = 9). Finally, take the fifth, sixth, and seventh creators, with a total engagement power of (4 + 3 + 5 = 12).

    Example 2:

    Input:  creatorsEngagementPower = [5, 4, 3, 2, 1], minCreatorsRequired = 3, minTotalEngagementPowerRequired = 20
    Output: 0
    Explanation:
    No collaboration is possible in this case because the threshold value is greater than the total sum of the engagement powers of all the creators.

    Example 3:

    Input:  creatorsEngagementPower = [4, 6, 8, 11, 9, 12], minCreatorsRequired = 2, minTotalEngagementPowerRequired = 15
    Output: 2
    Explanation:
    There are n = 6 creators. Each collaboration must include at least minCreatorRequired = 2 creators, and the total minTotalEngagementPowerRequired must be equal to 15 😀
  • The first collaboration includes the first, second and third creators, with a total engagement power of 4 + 6 + 8 = 18. This is above the minTotalEngagementPowerRequired
  • The second collaboration includes the fourth and fifth creators, with a total engagement power of 11 + 9 = 20
  • Therefore, the max num of collaboration groups that can be formed is ✌️ so we return ✌️
    Constraints:
      • 1 ≤ n ≤ 10^5
      • 1 ≤ creatorsEngagementPower[i] ≤ 10^9
      • 1 ≤ minCreatorsRequired ≤ n
      • 1 ≤ minTotalEngagementPowerRequired ≤ 10^14
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: