FastPrepSmallest Sufficient Team

Smallest Sufficient Team

Expedia logoExpedia● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Given a list of distinct required skills and the skills held by each person, return indices of a smallest team whose combined skills cover every required skill.

If several minimum-size teams exist, return the lexicographically smallest increasing index list. Every input has at least one sufficient team.

Function

smallestSufficientTeam(requiredSkills: String[], peopleSkills: String[][]) → int[]

Examples

Example 1

requiredSkills = ["java","sql","aws"]peopleSkills = [["java"],["sql"],["aws"],["java","sql"]]return = [2,3]

Case 1 exercises the documented deterministic contract.

Example 2

requiredSkills = ["a"]peopleSkills = [["a"]]return = [0]

Case 2 exercises the documented deterministic contract.

Example 3

requiredSkills = ["a","b"]peopleSkills = [["a"],["b"],["a","b"]]return = [2]

Case 3 exercises the documented deterministic contract.

Constraints

  • 1 <= requiredSkills.length <= 16.
  • 1 <= peopleSkills.length <= 60.
  • Skill names are case-sensitive; unrequired skills may be ignored.

More Expedia problems

See Expedia hiring insights
public int[] smallestSufficientTeam(String[] requiredSkills, String[][] peopleSkills) {
    // Write your code here.
}
requiredSkills["java","sql","aws"]
peopleSkills[["java"],["sql"],["aws"],["java","sql"]]
expected[2,3]
Checking account…