852. Smallest Skilled Team
A hackathon organiser needs a team that together knows every skill in skills, a list of distinct skill names. The candidate pool is people, where people[i] lists the skills candidate i knows (possibly none, with no repeats inside one list). Every name in people appears in skills.
Return the minimum number of candidates whose combined skills include every skill in skills. It is guaranteed that taking all candidates would cover every skill, so an answer always exists. Candidates may have identical skill lists but each is a separate person and can be picked once.
Example 1
- Input:
- skills = ["sql","css","kafka"]people = [["sql","css"],["kafka"],["css","kafka"],["sql"]]
- Output:
- 2
- Explanation:
People 0 and 1 together know sql, css and kafka; no single person knows all three, so the smallest team has 2 people.
Example 2
- Input:
- skills = ["rust","aws","ml","linux"]people = [["rust"],["aws"],["ml","linux"],["rust","aws","ml"],["linux"]]
- Output:
- 2
- Explanation:
The person knowing rust, aws and ml plus the person knowing linux form a team of 2 that covers everything.
Constraints
- 1 ≤ skills.length ≤ 16
- 1 ≤ people.length ≤ 60
- 0 ≤ people[i].length ≤ skills.length; names are short lowercase words
- The union of all candidates' skills equals the set skills
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
- Time per case
- Python 1,200 msC++ 300 msJava 600 msJavaScript 600 msTypeScript 600 ms
Expected complexity
- Time
- O(2^s * p)
- Space
- O(2^s)