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

本周的Tiktok OA 仍然是110分钟7道题,其中前5题是选择题,后面2题是算法题

6. 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.

You are given an integer n, representing the total number of TikTok users, along with two lists - influencers and followers - each of size n. For each index i, influencers[i] represents an influencer and followers[i] represents the user who follows that influencer. (If followers[i] is -1, it indicates that the corresponding influencer has no followers.)

It is important to note the following:

  1. Some users may not have any followers. In such cases, followers[i] will be set to -1, indicating that the corresponding influencer is not followed by anyone.
  2. There may be mutual follow relationships, i.e., user a may follow user b, and user b may follow user a.
  3. Some users might appear in the influencers list but not in the followers list. In such cases, assume these influencers follow nobody.
  4. 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

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 is propagated to influencer 3, who follows influencer 1. Influencer 3, in turn, propagates the trend to influencer 2, who follows influencer 3. As a result, the viral trend eventually reaches all the users.

Thus, 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

Complete the function findMinimumInfluencers in the editor below.

Function Parameters

  • int influencers[n]: an array where influencers[i] denotes the influencers
  • int 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

Input Format for Custom Testing

Sample Case 0

Sample Input 0
3  
2
3
1
1
2
3
Sample Output 0
1
Explanation

Consider introducing the viral trend to user 1 only. Since influencer 1 is followed by influencer 3, it is propagated to influencer 2, who follows influencer 3. As a result, the viral trend eventually reaches all the users. We therefore output 1.


Sample Case 1

Sample Input 1
5  
2
1
5
3
4
-1
1
5
3
5
3
Sample Output 1
3
Explanation

Consider introducing the viral trend to users 1, 2, and 4. Note that nobody follows influencer 2, so we must introduce the trend directly to influencer 2.

Since influencer 1 is followed by influencer 5, it is propagated to influencer 3, who follows influencer 5. Also note that both 5 and 3 are influencers and follow each other.

However, influencer 4 follows nobody, so it becomes necessary to introduce the viral trend to influencer 4 also. We therefore output 3.

7. 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).....

关注本站,或者添加联系方式,获取完整第七题

Follow this website or add contact information to get the complete seventh question

我们长期稳定承接各大科技公司如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 *