FastPrepCount Legal Outfit Combinations
Problems/Count Legal Outfit Combinations

Count Legal Outfit Combinations

Duolingo logoDuolingo● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report does not say how labels are cleaned up or what the input limits are. Our version is about 96% the same as the reported question.

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[][]) → long

Examples

Example 1

items = ["A","B","C"]illegalOutfits = [["A","B"],["A","C"]]return = 4

The 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 = 8

For 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 items is a distinct non-empty string.
  • 0 <= illegalOutfits.length <= 100.
  • Every row in illegalOutfits contains exactly two distinct labels from items.
  • 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

Duolingo interview experiences

  • Duolingo interviews · November 2026
  • Duolingo SWE Interview Questions: 3 Experiences
All Duolingo interview questionsSee Duolingo hiring insights
Saved
class Solution {
    public long countLegalOutfits(String[] items, String[][] illegalOutfits) {
        // Write your code here.
    }
}
Checking account…