Description
Solutions
TikTok Credits Distribution Challenge

In the grand finale of a prestigious TikTok tournament, the organizers have prepared several boxes filled with TikTok credits as prizes for the participants. They know exactly how many participants will compete in the tournament and want to ensure that every participant receives an equal number of TikTok credits to avoid any disappointment. The rules of the tournament are strict: once a prize box is opened, all the TikTok credits inside it must be distributed. The organizers need to determine whether they can distribute the TikTok credits in such a way that every participant gets the same number of credits.

Your task is to help the organizers tell the number of possible ways the credits can be distributed equally among all participants. If not possible, return 0.

Function Description

Complete the function canDistributeCredits in the editor.

canDistributeCredits has the following parameters:

  1. int participants: the number of participants
  2. int credits[n]: the number of credits in each box

Returns

int: Number of possible ways the credits can be distributed equally among all participants.

🌷, A Huge Thank You to the GG of Error-Free Excellence - Spike!༊

Example 1:

Input:  participants = 6, credits = [12, 18, 24, 36]
Output: 8
Explanation:

To determine if the TikTok credits can be distributed equally among the participants, follow these steps:

Total Credits Calculation: Calculate the total number of credits in any possible combination of boxes. Here, we need to check if the sum of any subset of the boxes' credits is divisible by the number of participants (6 in this case).

Checking Divisibility:

  • Sum of all boxes: 12+18+24+36=90
  • Dividing 90 by 6 gives 15 (90 is divisible by 6).
  • We need to check smaller combinations to see if the equal distribution is possible:
  • Boxes with 12, 18, and 24: 12+18+24=54
  • Dividing 54 by 6 gives 9 (54 is divisible by 6).
  • Boxes with 12 and 36: 12+36=48
  • Dividing 48 by 6 gives 8 (48 is divisible by 6).
  • And so on.

Conclusion: Since there are 8 combinations where the total number of credits is divisible by the number of participants (6), it is possible to distribute the credits equally.

Example 2:

Input:  participants = 5, credits = [7, 3, 6]
Output: 1
Explanation:
n/a
Constraints:
  • 1 <= n <= 106
  • 1 <= participants <= 103
  • 1 <= credits[i] <= 109
Thumbnail 0
Thumbnail 1
Testcase

Result
Case 1

input:

output: