Count Legal Outfit Combinations
Problem statement
You are given an array items of distinct clothing-item labels and an array illegalOutfits. Each row [a, b] in illegalOutfits identifies two different labels that may not appear together.
An outfit is a non-empty subset of items. An outfit is legal when it does not contain both labels from any forbidden pair. Repeated forbidden rows describe the same restriction.
Return the number of legal outfits as a signed 64-bit integer.
Function
countLegalOutfits(items: String[], illegalOutfits: String[][]) → longExamples
Example 1
items = ["A","B","C"]illegalOutfits = [["A","B"],["A","C"]]return = 4The legal non-empty subsets are [A], [B], [C], and [B, C]. Every other non-empty subset contains A together with B or C.
Example 2
items = ["hat","shirt","pants","shoes"]illegalOutfits = [["hat","shirt"],["pants","shoes"]]return = 8For each forbidden pair, choose neither label or exactly one of its two labels. The two independent pairs therefore produce 3 * 3 = 9 subsets including the empty subset, so there are 8 legal outfits.
Constraints
1 <= items.length <= 20.- Every value in
itemsis a distinct non-empty string. 0 <= illegalOutfits.length <= 100.- Every row in
illegalOutfitscontains exactly two distinct labels fromitems. - Repeated forbidden rows are allowed and represent the same restriction.
- The answer fits in a signed 64-bit integer.