本周的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:
- 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. - There may be mutual follow relationships, i.e., user
a
may follow userb
, and userb
may follow usera
. - Some users might appear in the
influencers
list but not in thefollowers
list. In such cases, assume these influencers follow nobody. - Some users might appear in neither the
influencers
list nor thefollowers
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 whereinfluencers[i]
denotes the influencersint followers[n]
: an array wherefollowers[i]
denotes the followers such thatfollowers[i]
followsinfluencers[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 to0
for all1 ≤ i ≤ n
followers[i]
is not equal toinfluencers[i]
for all1 ≤ 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.
