Team Formation
Updated
Problem statement
There are n developers, numbered 0 to n - 1. Developer i has skill i, so a smaller number means a lower skill, and no two developers have the same skill.
Each developer i has:
lowerSkill[i]: max number of team members with skill less than theirshigherSkill[i]: max number of team members with skill greater than theirs
Form the largest team such that every developer in it is okay with their relative skill position: for each member i, at most lowerSkill[i] other members have a lower skill and at most higherSkill[i] other members have a higher skill. Return the size of that team.
Function
formLargestTeam(lowerSkill: int[], higherSkill: int[]) → int Complete the function formLargestTeam in the editor.
formLargestTeam has the following parameters:
int[] lowerSkill:lowerSkill[i]is the most lower-skilled teammates developeriacceptsint[] higherSkill:higherSkill[i]is the most higher-skilled teammates developeriaccepts
The function returns an int: the size of the largest possible team.
Examples
Example 1
lowerSkill = [1, 3, 2, 2, 2]higherSkill = [2, 2, 1, 1, 3]return = 3Developers 0, 1 and 2 form a team of 3. In skill order:
- Developer 0 has 0 members below (allowed: up to 1) and 2 above (allowed: up to 2).
- Developer 1 has 1 below (up to 3) and 1 above (up to 2).
- Developer 2 has 2 below (up to 2) and 0 above (up to 1).
No team of 4 works. In a team of 4, the lowest member needs higherSkill at least 3, and only developer 4 has that. But developer 4 has the highest skill, so it cannot be the lowest member. So the answer is 3.
Constraints
1 ≤ lowerSkill.length ≤ 2 * 105higherSkill.length = lowerSkill.length0 ≤ lowerSkill[i], higherSkill[i] ≤ 2 * 105
More Agoda interview questions
- Sort Ones, Twos, and Threes In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Can Place FlowersPHONE SCREEN · Seen Nov 2026
- Reverse Words in a StringPHONE SCREEN · Seen Nov 2026
- Molecular Weight of a Grouped FormulaONSITE INTERVIEW · Seen Oct 2026
- Disk Space Window AnalyzerPHONE SCREEN · Seen Sep 2026
- Shortest Subarray With the Full DegreePHONE SCREEN · Seen Sep 2026
- Enumerate Weekly Work SchedulesPHONE SCREEN · Seen Sep 2026
- Count Values Appearing Exactly OncePHONE SCREEN · Seen Sep 2026
- Longest All-Present Attendance StreakPHONE SCREEN · Seen Sep 2026
- Chemical Formula WeightPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Hiking Club Fastest PaceInfosys · OAInfosys interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Minimum Cost of Every K-Capable Model SetTikTok · OATikTok interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions