[TikTok] OA 2025 start – 11 Mar (generic)

TikTok Viral Campaign

TikTok is a widely used social media platform where users follow influencers who shape their content preferences. Formally, if user A follows user B, then user A is said to be influenced by user B. Once a user is influenced by a trend, they immediately propagate this information to all users who follow them.

As a brand manager tasked with designing a viral campaign, your objective is to determine the minimum number of users who need to be initially targeted with the trend, such that the information eventually reaches every user on the platform.

If a user is neither an influencer nor a follower, they are still a TikTok user and must be directly introduced to the viral campaign independently.


Problem Details

You are given an integer n, representing the total number of TikTok users, along with two lists:

  • influencers: an array where influencers[i] represents an influencer.
  • followers: an array where followers[i] represents the user who follows the corresponding influencer.

Important Notes:

  • If followers[i] is -1, it indicates that the corresponding influencer has no followers.
  • There may be mutual follow relationships, i.e., user A may follow user B, and user B may follow user A.
  • Some users might appear in the influencers list but not in the followers list. In such cases, assume these influencers follow nobody.
  • Some users might appear in neither the influencers list nor the followers list. In such cases, assume these users neither follow nor influence anyone but are still considered individual TikTok users.

Your goal is to compute the size of the smallest set of users to whom the trend should initially be introduced, ensuring that the trend ultimately reaches every user on the platform.


Example

Given:

  • n = 4
  • influencers = [2, 1, 3, 4]
  • followers = [1, 3, 2, -1]

Consider introducing the viral trend to users 4 and 1.

  • Note that nobody follows influencer 4, so we must introduce the trend directly to influencer 4.
  • Once the trend is introduced to influencer 1, it propagates to influencer 3 (who follows influencer 1).
  • Influencer 3 then propagates the trend to influencer 2 (who follows influencer 3).

Thus, the viral trend reaches all users, and the minimum number of users required to initiate the trend is 2. It can be proven that it is not possible to achieve this with fewer than 2 users.


Function Description

Function Signature:

def findMinimumInfluencers(influencers: List[int], followers: List[int]) -> int:

Parameters:

  • influencers[n]: an array where influencers[i] denotes the influencer.
  • followers[n]: an array where followers[i] denotes the followers such that followers[i] follows influencers[i].

Returns:

  • int: the minimum number of influencers to whom the product should be introduced.

Constraints

  • 2 ≤ n ≤ 2 * 10^5
  • 1 ≤ influencers[i] ≤ n
  • 1 ≤ followers[i] ≤ n
  • followers[i] is not equal to 0 for all 1 ≤ i ≤ n
  • followers[i] is not equal to influencers[i] for all 1 ≤ i ≤ n

TikTok Content Clustering

TikTok has to deliver video content to users in an optimal manner. The system has a sequence of video chunks, represented by an array of integers videoChunks, where each element videoChunks[i] represents a chunk with an associated delivery cost (e.g., video quality, network usage, server load).

The task is to partition the sequence of video chunks into exactly k non-empty groups, such that the total cost of all the groups is minimized. The cost of a group (subarray) is defined as the sum of the costs of its first and last video chunk in that group.


Example

Given:

  • n = 5
  • videoChunks = [7, 8, 3, 9, 6]
  • k = 2

An optimal way is to divide the array into two subarrays: [[7, 8], [3, 9, 6]].

  • Cost of first subarray: 7 + 8 = 15
  • Cost of second subarray: 3 + 6 = 9

Thus, the total cost is 15 + 9 = 24. It can be proven that the minimum possible total cost is 24.


Function Description

Function Signature:

def getMinimumTotalCost(videoChunks: List[int], k: int) -> int:

Parameters:

  • videoChunks[n]: an array representing the chunks of videos to be grouped together.
  • k: an integer representing the number of partitions.

Returns:

  • long: representing the minimum possible total cost to partition into non-empty groups.

Constraints:

  • 1 ≤ n ≤ 10^5
  • 1 ≤ videoChunks[i] ≤ 10^9
  • 1 ≤ k ≤ n

Input Format for Custom Testing

Sample Case 0
Input:

videoChunks = [8, 9, 8, 2, 9, 9, 2]
k = 3

Output:

31

Explanation:

Given n = 7, videoChunks = [8, 9, 8, 2, 9, 9, 2], and k = 3. One of the optimal ways to partition the array is into these three subarrays: [[8, 9, 8], [2, 9, 9], [2]].

  • Cost of the first subarray: 8 + 8 = 16
  • Cost of the second subarray: 2 + 9 = 11
  • Cost of the third subarray: 2 + 2 = 4

Total cost = 16 + 11 + 4 = 31. It can be shown that the sum of the costs cannot be less than 31. Hence, the minimum total cost is 31.


我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *