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 Description
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 🐝!!
Example 1:
Input: favoriteCategories = [4, 2, 6, 8]
Output: 4
Explanation:Out 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:
Input: favoriteCategories = [3, 2, 5]
Output: 1
Explanation:The 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:
Input: favoriteCategories = [4, 8, 2, 16]
Output: 8
Explanation:Educated guess: The highest number of common interests between any pair of users in the network.
2 ≤ n ≤ 10^4
.1 ≤ favoriteCategories[i] ≤ 10^4

input:
output: