#1125

Smallest Sufficient Team

expert · 1285 · lc hard +32 · verified · 55.4% accepted · 2,269 likes · top 49%

Description

You have a set of required skills req_skills and a list of people, where people[i] is the list of skills person i has. A sufficient team covers every required skill.

Return any smallest sufficient team as a list of person indices. An answer is guaranteed to exist.

Example 1:

Input: req_skills = ["java","nodejs","reactjs"], people = [["java"],["nodejs"],["nodejs","reactjs"]]
Output: [0,2]

Example 2:

Input: req_skills = ["algorithms","math","java","reactjs","csharp","aws"], people = [["algorithms","math","java"],["algorithms","math","reactjs"],["java","csharp","aws"],["reactjs","csharp"],["csharp","math"],["aws","java"]]
Output: [1,2]

Code

1
2
3