Detailed Video Solution | Java Python
\n\n\nclass Solution {\n    public int[] smallestSufficientTeam(String[] req_skills, List<List<String>> people) {\n        int n = req_skills.length, m = people
<iframe width="560" height="315" src="https://www.youtube.com/embed/RyMJzEAQpfg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>\n\n```\nclass Solution {\n    public int[] smallestSufficientTeam(String[] req_skills, List<List<String>> people) {\n        int n = req_skills.length, m = people.size();\n        HashMap<String, Integer> map = new HashMap<>();\n        for (int i = 0; i < n; ++i)\n            map.put(req_skills[i], i);\n        List<Integer>[] dp = new List[1 << n];\n        dp[0] = new ArrayList<>();\n        \n        int[] skillPerson = new int[m];\n        for (int i = 0; i < m; i ++) {\n            List<String> list = people.get(i);\n            int val = 0;\n            for (String skill : list) {\n                val |= 1 << map.get(skill);\n            }\n            skillPerson[i] = val;\n        }\n        boolean[] banned = new boolean[m];\n        for (int i = 0; i < m; i ++) {\n            for (int j = i + 1; j < m; j ++) {\n                int val = skillPerson[i] | skillPerson[j];\n                if (val == skillPerson[i]) {\n                    banned[j] = true;\n                } else if (val == skillPerson[j]) {\n                    banned[i] = true;\n                }\n            }\n        }\n        for (int i = 0; i < m; i++) {\n            if(banned[i]) continue;\n            int cur_skill = skillPerson[i];\n            \n            for (int j = 0; j < dp.length; j++) {\n                if (dp[j] == null) continue;\n                int comb = j | cur_skill;\n                if (dp[comb] == null || dp[j].size() + 1 < dp[comb].size()) {\n                    dp[comb] = new ArrayList<>(dp[j]);\n                    dp[comb].add(i);\n                }\n            }\n        }\n        return dp[(1 << n) - 1].stream().mapToInt(i -> i).toArray();\n    }\n}\n```\n\n```\nclass Solution:\n    def smallestSufficientTeam(self, req_skills: List[str], people: List[List[str]]) -> List[int]:\n        n = len(req_skills)\n        m = len(people)\n        skillMap = {skill: i for i, skill in enumerate(req_skills)}\n        dp = [None] * (1 << n)\n        dp[0] = []\n\n        skillPerson = []\n        for i in range(m):\n            val = 0\n            for skill in people[i]:\n                val |= 1 << skillMap[skill]\n            skillPerson.append(val)\n\n        banned = [False] * m\n        for i in range(m):\n            for j in range(i + 1, m):\n                val = skillPerson[i] | skillPerson[j]\n                if val == skillPerson[i]:\n                    banned[j] = True\n                elif val == skillPerson[j]:\n                    banned[i] = True\n\n        for i in range(m):\n            if banned[i]:\n                continue\n            curSkill = skillPerson[i]\n\n            for j in range(len(dp)):\n                if dp[j] is None:\n                    continue\n                comb = j | curSkill\n                if dp[comb] is None or len(dp[j]) + 1 < len(dp[comb]):\n                    dp[comb] = dp[j] + [i]\n\n        return dp[(1 << n) - 1]\n```\n\n\n\n\n\n
['Python', 'Java']