Skip to the code
cf.
+25 XP

#293 Distinct Label Bundles

medium

An issue tracker stores label IDs on a ticket in labels, and the same label ID can appear more than once. A bundle is any collection of these labels, using each entry at most once.

Two bundles are the same if they contain the same IDs the same number of times, no matter which entries they came from. Write distinctBundles(labels) that returns every distinct bundle, including the empty one, each sorted ascending.

The bundles may be in any order, but each distinct bundle must appear exactly once.

Example 1

Input: labels = [1,2,2]
Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]

Taking the first 2 or the second 2 gives the same bundle, so [2] and [1, 2] appear once each.

Example 2

Input: labels = [3,3]
Output: [[],[3],[3,3]]

The bundles differ only in how many 3s they hold.

Constraints

  • 0 <= labels.length <= 10
  • -10 <= labels[i] <= 10
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).