Maximize Collaboration
Learn this problemProblem statement
As a data analyst at TikTok, 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 (sum of their powers) of the team must meet or exceed a threshold (given by
minTotalEngagementPowerRequired) to ensure the collaboration generates enough buzz to go viral.
Given a list of 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 — once they're in a team, they cannot join another.
Complete the function createMaximumCollaborations in the editor.
createMaximumCollaborations has the following parameter(s):
int creatorsEngagementPower[n]: An array that denotes the engagement power of each creator.int minCreatorsRequired: The minimum number of creators required in a collaboration.long minTotalEngagementPowerRequired: The minimum total engagement power required for a collaboration.
int: The maximum number of collaborations that can be formed from the creators.
Function
createMaximumCollaborations(creatorsEngagementPower: int[], minCreatorsRequired: int, minTotalEngagementPowerRequired: long) → intExamples
Example 1
creatorsEngagementPower = [4, 4, 3, 6, 4, 3, 5]minCreatorsRequired = 2minTotalEngagementPowerRequired = 8return = 3One 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
creatorsEngagementPower = [5, 4, 3, 2, 1]minCreatorsRequired = 3minTotalEngagementPowerRequired = 20return = 0No 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
creatorsEngagementPower = [4, 6, 8, 11, 9, 12]minCreatorsRequired = 2minTotalEngagementPowerRequired = 15return = 2There are n = 6 creators. Each collaboration must include at least minCreatorsRequired = 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 maximum number of collaboration groups that can be formed is 2.
Constraints
1 ≤ n ≤ 10^51 ≤ creatorsEngagementPower[i] ≤ 10^91 ≤ minCreatorsRequired ≤ n1 ≤ minTotalEngagementPowerRequired ≤ 10^14