Imagine you're a community manager at TikTok, tasked with building teams for a high-stakes influencer marketing campaign. You have a list of influencers, each with an engagement score based on their recent activity. Your goal is to form the largest squad of influencers who can collaborate seamlessly.
For any team to work well together, the difference between the engagement scores of two consecutive influencers in the squad must be either 0 or 1. If the difference between consecutive influencers is greater than 1, they won't vibe well!
Given the engagement_scores
of n
influencers, your task is to find the largest possible squad where all members can collaborate smoothly.
Note: You are allowed to rearrange the influencers to maximize team potential!
Function Description
Complete the function findMaxSquadSize
in the editor.
findMaxSquadSize
has the following parameter:
int[] engagement_scores
: an array of integers representing the engagement scores of influencers
Returns
int
: the size of the largest squad
⸜(。˃ ᵕ ˂ )⸝♡ Credit to A 🌷༊·˚
Example 1:
Input: engagement_scores = [12, 14, 15, 11, 16]
Output: 3
Explanation:Valid squads of influencers are {11, 12} and {14, 15, 16}. These squads have sizes 2 and 3, respectively, so the largest squad size is 3.
Example 2:
Input: engagement_scores = [1, 13, 2, 3]
Output: 3
Explanation:There are 2 valid squads possible ->> {1, 2, 3} and {13}. These have sizes of 3 and 1, respectively, so the largest squad size is 3 :)
Example 3:
Input: engagement_scores = [10, 10, 10, 10, 11]
Output: 5
Explanation:All the influencers can be in the same squad {10, 10, 10, 10, 11}, so the largest squad size is 5 🦥
1 <= n <= 105
1 <= engagement_scores[i] <= 109


input:
output: