Enumerate Distinct Audience Bundles From Repeated Segment Tags
Last updated: November 29, 2026
Quick Overview
Given a list of audience segment tags that may contain duplicates, return every distinct bundle (sub-multiset) of tags, including the empty bundle. Two bundles are the same if they contain the same tags with the same counts.
Meta
November 29, 20260
0
0 solved
Given a list of audience segment tags that may contain duplicates, return every distinct bundle (sub-multiset) of tags, including the empty bundle. Two bundles are the same if they contain the same tags with the same counts.
Meta ads targeting combines segments, and an internal tool that previews every bundle must not list the same bundle twice. The interviewer checks the sort-then-skip-duplicates rule at each recursion depth, a common place for candidates to slip.
What the Interviewer Expects
- Sort so equal tags are adjacent
- Record a subset at every node of the recursion tree
- Skip an equal value at the same depth, not across depths
- Avoid a set of tuples as the dedup strategy
- State the output-sensitive complexity
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return only bundles of size exactly k?
- How would you count distinct bundles without listing them?
- How would you enforce that some tags are mutually exclusive?
- Can you generate them iteratively?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input up to 10 tags with repeats.
- Output every distinct sub-multiset once, any order.
- Inner order within a bundle does not matter....
High-Level Design
Sort the tags. In the recursive call starting at index start, record the current bundle, then try each index i >= start as the next tag. If i > start and tags[i] == tags[i-1], skip it: picking...