Count Legal Outfit Combinations
Updated
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.
More Duolingo interview questions
- Bouncing Square Reaches a Screen CornerOA · Seen Dec 2024
- Most-Read Page Across Every Valid StorylineOA · PHONE SCREEN · Seen Oct 2022
- Shortest Route Through a Traced MazeOA · Seen Sep 2022
- Rank Common Translation MistakesOA · Seen Sep 2022
- Count Distinct Word MeaningsOA · Seen Sep 2021
- Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
- Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
- Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
- Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
- Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Alternating Parity PermutationsGoldman Sachs · OAGoldman Sachs interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- SubsetsTemu · PHONE SCREENTemu interview questions
- Expand Attribute CombinationsPinterest · PHONE SCREENPinterest interview questions
- Maximum Unique-Character Word SubsetMeta · ONSITE INTERVIEWMeta interview questions
- Count String Pairs With Disjoint CharactersNetflix · PHONE SCREENNetflix interview questions
- Generate Circular Student ArrangementsAmazon · ONSITE INTERVIEW
- SubsetsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- SubsetsGoogle · ONSITE INTERVIEWGoogle interview questions
- Winning Draws for a Mahjong HandZip · PHONE SCREENZip interview questions