Skip to the code
cf.
+50 XP

#560 Smallest Team Covering Every Skill

hard

A new frontend project needs every skill in skills. Candidate i has the skills listed in people[i]. A team covers a skill if at least one member has it.

Write smallestTeam(skills, people) that returns the fewest people whose combined skills cover every required skill. Some team always exists.

Example 1

Input: skills = ["react","css","node"], people = [["react"],["css","node"],["react","css"]]
Output: 2

People 0 and 1 together know all three skills; nobody knows all three alone.

Example 2

Input: skills = ["a11y"], people = [["a11y"]]
Output: 1

One person covers the only skill.

Constraints

  • 1 <= skills.length <= 16
  • 1 <= people.length <= 60
  • Each person lists between 0 and 16 skills, all from skills.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).