Round 1
Questions:
Q1] 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.
Example
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.
Function Description
Complete the function canDistributeCredits in the editor below.
canDistributeCredits has the following parameters):
int participants: the number of participants.
int credits[n]: the number of credits in each box.
Returns
int: Number of possible ways the credits can be distributed equally among all.
Q2] 6. ViralContentBalancer
The TikTok engineering team is developing a new feature for analyzing viral trends by studying content sequences represented by a string content of length n, consisting of lowercase alphabets. The team has discovered that to make a video go viral, each element (character) in the content sequence should have an equal frequency.
In one operation, a character can be appended or removed from the content string.
Your task is to find the minimum number of operations required to balance the frequency of all characters in the content sequence.
Example
Input:
content = "xzyzxa"
Output:
2
Explanation:
For the content "xzyzxa", the characters 'Z' and 'X' have higher frequencies than others. To balance the frequency of all characters, one possible solution is to append one 'a' and one 'y', resulting in content = "xzyzxaya". Alternatively, removing one 'x' and one 'z' would also achieve a balanced distribution, with the new content sequence content = "xyza".
Both approaches result in a valid balanced content sequence, and the minimum number of operations required is 2.
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.