TikTok Viral Challenge
In the competitive world of social media, especially on platforms like TikTok, creators are constantly battling to produce viral content. The stakes are high-every video segment counts. As a data analyst working for TikTok, you've been tasked with a critical mission: to help creators optimize their videos by identifying the most promising segments that could lead to viral success.
Each segment of a TikTok video has an engagement attribute, which reflects its potential to go viral. This attribute is represented as an integer array engagementArray of size 26, corresponding to the letters of the alphabet ('a' to '2). Each element in this array is either "1' (indicating a viral segment) or '0' (indicating a non-viral segment).
The goal is to count all possible viral content combinations. A TikTok video is considered viral if the number of non-viral segments in any substring of the video does not exceed a given threshold k.
The video is represented by a string of length n.
Given:
Find the number of unique non-empty substrings of the video that qualify as viral content.
Input Format for Custom Testing:
Input from stdin will be processed as follows and passed to the function.
The first line contains a string, video,
The next line contains an integer 26, the size of the engagementArray.
Each of the next 26 lines contains an integer, engagementArray[i].
The next line contains an integer, k.
Function Description
Complete the function countViralCombinations in the editor below.
countViralCombinations has the following parameter(s):
string video: A string representing the lineup of TikTok segments, where each character corresponds to a segment's unique attribute or engagement level.
int engagementArray[n]: An array of integers where each element is either '1' (indicating a viral segment) or '0' (indicating a non-viral segment). This array aligns with the English alphabet; for instance, a corresponds to the first element.
int k: An integer denoting the maximum number of non-viral segments allowed in any content formation to consider it viral.
Returns
int: an integer denoting the number of unique content formations that meet the criteria of having no more than k non-viral segments, ensuring each formation is considered viral.
Constraints
1 ≤ n≤ 1500.
1 ≤ k≤n.
engagementArray[i] € {0, 1}
Sample case 0:
stream video = "stream"
engagementArray size = 26
engagementArray = [0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
k = 2
Output = 14
Another test case: Best for our unerstanding
Input:
video= "abc"
engagementArray = [0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
k = 2
Output: 5
Explanation:
This is a brute force solution, for subarray's:
def countViralCombinations(video, engagementArray, k):
res = 0
n = len(video)
for i in range(n):
weak = 0
for j in range(n):
if engagementArray[ord(video[j]) - ord('a')] != 1:
weak += 1
if weak < k:
res += 1
return res
video = "abc"
engagementArray = [0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
k = 2
print("result", countViralCombinations(video, engagementArray, k))
Please UPVOTE!!!!!!
any other solution's or approaches would be appreciated!