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. - There may be mutual follow relationships, i.e., user
amay follow userb, and userbmay follow usera. - Some users might appear in the
influencerslist but not in thefollowerslist. In such cases, assume these influencers follow nobody. - Some users might appear in neither list. In such cases, assume these users neither follow nor influence anyone, but they 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 = [1, 2, 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.
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
This problem asks for the minimum number of starting users needed so that influence eventually reaches every user in a directed graph. Build edges from each influencer to the corresponding follower, compute strongly connected components, and then count how many condensed components have zero in-degree. Those components must each be chosen as an initial source because nothing outside can reach them. The graph may include one-way links, mutual follows, and users that appear only partially in the input, so the solution should handle all users explicitly and run efficiently with SCC decomposition.