Smallest Sufficient Team - Problem
Team Building Challenge

Imagine you're a project manager who needs to assemble the smallest possible team for a critical project. You have a list of req_skills that are absolutely necessary for the project's success, and a pool of candidates where each person has their own unique set of skills.

Your mission: Find the minimum number of people needed to cover ALL required skills.

For example, if your project needs ["java", "nodejs", "reactjs"] and you have candidates with skills like:
• Person 0: ["java"]
• Person 1: ["nodejs"]
• Person 2: ["nodejs", "reactjs"]

The optimal team would be [0, 2] - just 2 people to cover all 3 required skills!

Goal: Return the indices of team members in the smallest sufficient team. Any valid minimum-size team is acceptable.

Input & Output

example_1.py — Basic Team Assembly
$ Input: req_skills = ["java","nodejs","reactjs"] people = [["java"],["nodejs"],["nodejs","reactjs"]]
Output: [0,2]
💡 Note: Person 0 provides Java, Person 2 provides both NodeJS and ReactJS. Together they cover all required skills with just 2 team members.
example_2.py — Overlapping Skills
$ 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]
💡 Note: Person 1 covers [algorithms, math, reactjs] and Person 2 covers [java, csharp, aws]. Together they provide all 6 required skills efficiently.
example_3.py — Single Person Solution
$ Input: req_skills = ["python","django"] people = [["python"],["django"],["python","django","flask"]]
Output: [2]
💡 Note: Person 2 alone has both required skills (python and django), making them a complete one-person team. Even though they have an extra skill (flask), they're still optimal.

Visualization

Tap to expand
🦸‍♂️ Superhero Team AssemblyAvailable Heroes:HERO 0Java Master001HERO 1Python Sage010HERO 2React Wizard100Required Powers:JavaPythonReactTarget: 111 (binary)🎯 Optimal Team Formation:Step 1: Try Hero 0 (001) + Hero 1 (010)001 | 010 = 011 (Java + Python)Step 2: Add Hero 2 (100) to complete team011 | 100 = 111 (All Powers!)🏆 Minimum Team: Heroes [0, 1, 2]⚡ Bitwise Magic:Binary Operations are Lightning Fast!• Set Union → Bitwise OR (|)• Skill Check → Bitwise AND (&)• Coverage → Compare with TargetTime: O(people × 2^skills)
Understanding the Visualization
1
Map Powers to Bits
Each superpower gets a unique bit position - Java is bit 0, Python is bit 1, React is bit 2
2
Heroes Become Binary
Each hero's power set becomes a binary number - Hero with Java+Python becomes '011'
3
Smart Team Building
Use DP to systematically build teams, combining power sets with bitwise OR operations
4
Find Optimal Squad
The smallest team covering all powers (111 in binary) is our answer!
Key Takeaway
🎯 Key Insight: By representing skill sets as bitmasks, we transform set operations into ultra-fast bitwise operations, making the solution both elegant and efficient!

Time & Space Complexity

Time Complexity
⏱️
O(people × 2^skills)

For each of 2^skills possible coverage masks, we check each person

n
2n
Linear Growth
Space Complexity
O(2^skills × people)

DP array stores best team for each skill coverage pattern

n
2n
Linear Space

Constraints

  • 1 ≤ req_skills.length ≤ 16
  • 1 ≤ people.length ≤ 60
  • 1 ≤ people[i].length, req_skills[i].length, people[i][j].length ≤ 16
  • Elements of req_skills and people[i] consist of lowercase English letters
  • It is guaranteed an answer exists
Asked in
Google 45 Amazon 38 Microsoft 29 Meta 22
67.2K Views
Medium-High Frequency
~25 min Avg. Time
1.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen