FastPrepInfluencers Squad

Influencers Squad

TikTok logoTikTok● EasyINTERNOA

Problem statement

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

findMaxSquadSize(engagement_scores: int[]) → int

Complete the function findMaxSquadSize in the editor.

findMaxSquadSize has the following parameter:

  1. int[] engagement_scores: an array of integers representing the engagement scores of influencers

Returns int: the size of the largest squad

Examples

Example 1

engagement_scores = [12, 14, 15, 11, 16]return = 3

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

engagement_scores = [1, 13, 2, 3]return = 3

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

engagement_scores = [10, 10, 10, 10, 11]return = 5

All the influencers can be in the same squad {10, 10, 10, 10, 11}, so the largest squad size is 5 🦥

Constraints

  • 1 <= n <= 105
  • 1 <= engagement_scores[i] <= 109

More TikTok problems

See TikTok hiring insights
Saved
public int findMaxSquadSize(int[] engagement_scores) {
  // write your code here
}
engagement_scores[12, 14, 15, 11, 16]
expected3
Checking account…