AO
Back

Largest Hackathon Team Under Skill-Rank Constraints

OAAsync OALast reported October 2025Low Frequency

Problem Overview

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:

  • Skill level 1: two team members have a higher skill level, and higherSkill[1] = 2.
  • Skill level 3: one member is lower and one is higher (lowerSkill[3] = 2, higherSkill[3] = 1).
  • Skill level 4: two members are lower (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 accepts
  • higherSkill[n]: the most team members with a higher skill level that each developer accepts
  • Returns int: the maximum number of developers on a team

Constraints

  • 1 ≤ n ≤ 2 * 10^5
  • 0 ≤ lowerSkill[i], higherSkill[i] < n

The 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 Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
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.

What Reports Emphasize

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

Practice

Write your own against 8 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Citadel with friends?

Send them this page. It is free to read, no account needed.

More Citadel Questions

Free preview

Every question in the Citadel catalog gets this depth

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.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Citadel · OA · Reported 2× across candidate reports
Is this helpful?