Trains the technique from
LeetCode 90Subsets IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A machinist keeps a tray of steel shims. Each shim is stamped with its thickness deviation in microns, given by the array shims, and a deviation may be negative when the shim runs under nominal. Two shims can carry the same stamp, and the tray may hold several such twins.
To pack a gap the machinist assembles a stack by taking any number of shims off the tray, from none at all up to the entire tray. A stack behaves purely as a collection of stamps: the order the shims were lifted in changes nothing, so two stacks are the same job when they hold each stamp the same number of times. Twins stamped alike are interchangeable, which is why lifting the first twin or the second twin yields one stack, not two, while lifting both twins yields a different stack from lifting one.
Produce every stack the tray permits, each one listed exactly once and with no repeats between them. The empty stack counts as a stack. Neither the order of the stacks in your answer nor the order of the stamps inside a stack is judged.
Example 1
Two shims share the stamp 4. Lifting either one alone gives the same stack, so [4] appears once, while lifting both gives the separate stack [4, 4].
Example 2
With three identical stamps the only choice is how many to lift, which gives four stacks holding zero, one, two and three shims.
Example 3
Nothing repeats here, so every combination of the two shims is already distinct.
The groups you return, and the values inside each group, may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def distinct_shim_stacks(shims: list[int]) -> list[list[int]]:public List<List<Integer>> distinctShimStacks(int[] shims)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.