Skip to the code
cf.
+25 XP

#675 Smallest Team Covering Skills

medium

A project needs every skill in required. people[i] lists the skills of person i. A team covers a skill if at least one member has it.

Write smallestTeam(people, required) that returns the size of the smallest team covering every required skill, or -1 if no team can. If required is empty, the answer is 0.

Example 1

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

Person 0 covers react and person 2 covers node and sql. No single person covers all three.

Example 2

Input: people = [["go"],["rust"]], required = ["java"]
Output: -1

Nobody knows java.

Constraints

  • 1 <= people.length <= 15
  • 0 <= required.length <= 16, all distinct
  • Skills are short lowercase strings.
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).