Panda Guru LogoPanda
Guru

TikTok OA Backend Software Engineer 2024

Round 1

Questions: 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 'z'). 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:

  1. A string video of length n.
  2. An integer k, the maximum allowed number of non-viral segments in a viral TikTok video.
  3. An integer array engagementArray of size 26, where each element is either '1' (viral) or '0' (non-viral).

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.

Function Description
Complete the function countViralCombinations in the editor below.

countViralCombinations has the following parameter(s):

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

Sample case 0:

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 understanding
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:

  1. "a" - 1 weak player - viral
  2. "b" - 0 weak players - viral
  3. "c" - 1 weak player - viral
  4. "ab" - 1 weak player - viral
  5. "bc" - 1 weak player - viral
  6. "abc" - 2 weak players - it is equal to k so - non-viral

This is a brute force solution, for subarrays:

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 solutions or approaches would be appreciated!

Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.