def getOptimalTeamSize(lowerSkill: list[int], higherSkill: list[int]) -> int:
There are n developers, and the skill level of the i-th developer is i, for 1 ≤ i ≤ n. The task is to form a team of developers for a hackathon. A developer agrees to be on the team only if certain conditions are met.
Given two arrays, lowerSkill and higherSkill, the i-th developer will join the team if at most lowerSkill[i] team members have a lower skill level than them, and at most higherSkill[i] team members have a higher skill level than them.
Select the largest possible team such that every developer on the team agrees with the team composition. Return the number of developers on that team.
Example
n = 5
lowerSkill = [1, 3, 2, 2, 2]
higherSkill = [2, 2, 1, 1, 3]
getOptimalTeamSize(lowerSkill, higherSkill) -> 3
It is optimal to select the developers with skill levels 1, 3 and 4:
higherSkill[1] = 2.lowerSkill[3] = 2, higherSkill[3] = 1).lowerSkill[4] = 2).All three are content, and no team of four works.
Function
Complete getOptimalTeamSize(lowerSkill, higherSkill):
lowerSkill[n]: the most team members with a lower skill level that each developer acceptshigherSkill[n]: the most team members with a higher skill level that each developer acceptsint: the maximum number of developers on a teamConstraints
1 ≤ n ≤ 2 * 10^50 ≤ lowerSkill[i], higherSkill[i] < nThe statement counts developers from 1 (lowerSkill[1] is the developer with skill level 1). In Python the lists are 0-indexed, so lowerSkill[0] belongs to skill level 1.
Two reports describe this problem, both from Citadel online assessments.
The first (July 2025, SDE campus 2025-2026) had two problems: a four-way array split maximising a gross value, then this one, with n up to 2 * 10^5. The poster wrote a memoized top-down DP, O(n^3), which passed about a third of the test cases; the failures were recursion-stack overflows, and pruning did not help. They suspected the optimal solution was O(n log n), binary search on the answer with an O(n) greedy check, but could not see the greedy because both ends are constrained. A reply supplied it: for a target size x, take as the y-th member the first developer who fits (with the comparison direction then corrected by the poster), with an exchange-argument proof, O(n log n) overall and in the reply's view hard to improve to O(n). The poster confirmed it was right. Another reply says they had just taken the OA and written a version that passed every test; no code was posted.
The second (October 2025) posted the statement verbatim, including the function name getOptimalTeamSize and the constraints, alongside a problem about achievable MEX values. The poster, who lists this problem first, wrote that after finishing the first problem they found they had misread it, and that they did not finish the last one; they also said one of the questions took about ten minutes just to understand.
There are n developers, and the skill level of the i-th developer is i, for 1 ≤ i ≤ n. The task is to form a team of developers for a hackathon. A developer agrees to be on the team only if certain conditions are met.
Given two arrays, lowerSkill and higherSkill, the i-th developer will join the team if at most lowerSkill[i] team members have a lower skill level than them, and at most higherSkill[i] team members have a higher skill level than them.
Select the largest possible team such that every developer on the team agrees with the team composition. Return the number of developers on that team.
Example
n = 5
lowerSkill = [1, 3, 2, 2, 2]
higherSkill = [2, 2, 1, 1, 3]
getOptimalTeamSize(lowerSkill, higherSkill) -> 3
It is optimal to select the developers with skill levels 1, 3 and 4:
higherSkill[1] = 2.lowerSkill[3] = 2, higherSkill[3] = 1).lowerSkill[4] = 2).All three are content, and no team of four works.
Function
Complete getOptimalTeamSize(lowerSkill, higherSkill):
lowerSkill[n]: the most team members with a lower skill level that each developer acceptshigherSkill[n]: the most team members with a higher skill level that each developer acceptsint: the maximum number of developers on a teamConstraints
1 ≤ n ≤ 2 * 10^50 ≤ lowerSkill[i], higherSkill[i] < nThe statement counts developers from 1 (lowerSkill[1] is the developer with skill level 1). In Python the lists are 0-indexed, so lowerSkill[0] belongs to skill level 1.
| Approach | Notes |
|---|---|
| Top-down DP with memoization over (members taken, members still allowed above, index) | O(n^3). The poster who wrote it passed about a third of the tests; the rest overflowed the recursion stack, and constant-factor pruning did not help. The poster thought a bottom-up version would pass more tests but still be far too slow for n = 2 * 10^5. |
Common mistakes: An O(n^3) DP, which is far too slow for n = 2 * 10^5; Top-down recursion overflowing the recursion stack at n = 2 * 10^5; Writing the greedy check's comparisons the wrong way round (<= instead of >=); the arrays are upper bounds; Misreading the statement: one poster, who lists this problem first, found after finishing the first problem that they had misread it
What passers do: A reply gave binary search on the team size with a first-fit greedy check and an exchange-argument proof, O(n log n); the poster confirmed it was correct; Another reply reports writing a version that passed every test (no code posted)
Why people fail: An O(n^3) memoized DP passed about a third of the tests; the failing ones overflowed the recursion stack; One candidate misread the first problem they solved (this one, by the order of their post) and did not finish the last problem
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 62 Citadel questions, refreshed monthly from new candidate reports.