Max Shared Categories
Learn this problemProblem statement
In the dynamic world of TikTok, each user has a list of favorite content categories they are interested in. You are tasked with analyzing the connections between these users, focusing specifically on the number of shared interests. The goal is to determine the highest number of common interests that any pair of TikTok users shares, where the number of common interests is the largest positive integer that evenly divides the number of interests of both users.
You are given an array favoriteCategories of length n where each element represents the number of favorite content categories of a TikTok user. Find the highest number of common interests between any two TikTok users in the network.
Function
maxSharedCategories(favoriteCategories: int[]) → int
Complete the function maxSharedCategories in the editor.
maxSharedCategories has the following parameter(s):
int favoriteCategories[n]: an array where each element represents the number of favorite content categories of a TikTok user.
Returns
int: the highest number of common interests between any pair of users in the network.
🐾 Introduce our top-tier GG of Error-Free Excellece --> 🐳 spike 🐝!!
Examples
Example 1
favoriteCategories = [4, 2, 6, 8]return = 4Out of all the pairs possible from the array, the maximum number of common interests (the largest positive integer that evenly divides the number of favorite content categories of both users) is between the users with 4 and 8 favorite content categories. The number of common interests is 4, which is the highest possible value.
Example 2
favoriteCategories = [3, 2, 5]return = 1The maximum possible number of common interests between any pairs of TikTok users from the array is 1 since all the pairs of users have favorite categories that are relatively prime (no common interests other than 1).
Example 3
favoriteCategories = [4, 8, 2, 16]return = 8Educated guess: The highest number of common interests between any pair of users in the network.
Constraints
2 ≤ n ≤ 10^4.1 ≤ favoriteCategories[i] ≤ 10^4
More Tiktok problems
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026
- Obstacle Placement QueriesOA · Seen Jul 2026
- Repeated Grouped Digit SumOA · Seen Jul 2026
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026