Fewest People Covering Every Required Skill

Quick Overview

Fewest People Covering Every Required Skill. Choose a smallest-size set of people whose combined skills cover every string in req_skills.

Fewest People Covering Every Required Skill

Company: Airbnb

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Choose a smallest-size set of people whose combined skills cover every string in req_skills. Return their original zero-based indices in any order. At least one sufficient team exists, and any team of minimum size is valid. ```cpp class Solution { public: vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people); }; ``` ### Examples **Example 1:** ```text Input: req_skills = ["a","b"], people = [["a"],["b"],["a","b"]] Output: [2] Explanation: Person2 alone has both required skills, and no empty team can cover them. ``` **Example 2:** ```text Input: req_skills = ["x","y","z"], people = [["x","y"],["y","z"],["x"]] Output: [0,1] Explanation: These two cover all three skills; no person covers all three alone. ``` ### Constraints - There are 1 to 16 distinct required skills, each a lowercase word of length 1 to 16. - There are 1 to 60 people. Each person lists 0 to 16 distinct skills. - Every listed skill has length 1 to 16, uses lowercase letters and belongs to req_skills. - A sufficient team is guaranteed to exist. ### Contract considerations Indices refer to original people positions. Preserve every required skill even when several people overlap. ```hint Read the boundary condition May a returned person index occur more than once, and does overlapping expertise remove any required skill? ``` ### What a Strong Answer Covers Indices refer to original people positions. Preserve every required skill even when several people overlap. ### Follow-up Questions Optional practice extension, separate from the original task: How would different costs per person change the state objective?

Overview: Fewest People Covering Every Required Skill. Choose a smallest-size set of people whose combined skills cover every string in req_skills.

Airbnb logo
Airbnb
Source window: 0–6 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Choose a smallest-size set of people whose combined skills cover every string in req_skills. Return their original zero-based indices in any order. At least one sufficient team exists, and any team of minimum size is valid.

class Solution {
public:
    vector<int> smallestSufficientTeam(vector<string>& req_skills, vector<vector<string>>& people);
};

Examples

Example 1:

Input: req_skills = ["a","b"], people = [["a"],["b"],["a","b"]]
Output: [2]
Explanation: Person2 alone has both required skills, and no empty team can cover them.

Example 2:

Input: req_skills = ["x","y","z"], people = [["x","y"],["y","z"],["x"]]
Output: [0,1]
Explanation: These two cover all three skills; no person covers all three alone.

Constraints

  • There are 1 to 16 distinct required skills, each a lowercase word of length 1 to 16.
  • There are 1 to 60 people. Each person lists 0 to 16 distinct skills.
  • Every listed skill has length 1 to 16, uses lowercase letters and belongs to req_skills.
  • A sufficient team is guaranteed to exist.

Contract considerations

Indices refer to original people positions. Preserve every required skill even when several people overlap.

What a Strong Answer Covers Guidance

Indices refer to original people positions. Preserve every required skill even when several people overlap.

Follow-up Questions Guidance

Optional practice extension, separate from the original task: How would different costs per person change the state objective?