Subsets
Real-world version: Every Gain PresetThe statement here is our own: the same inputs, outputs and technique.
A mixing desk exposes a bank of gain trims, given as the integer array offsets. Every trim in the bank carries a different value, and a value may be negative (a cut) or positive (a boost).
A preset is any selection of trims to engage. Engaging none of them is a preset, and so is engaging the whole bank. Build the catalogue of every preset the desk can hold.
Each preset must list its engaged trims in the same relative order they occupy in offsets. The catalogue itself may come back in any order.
Examples
Example 1
- Input
- offsets = [4, -2]
- Output
- [[], [4], [-2], [4, -2]]
Two trims give four presets: nothing engaged, each one alone, and both together with 4 still listed ahead of -2.
Example 2
- Input
- offsets = [7]
- Output
- [[], [7]]
A single trim is either idle or engaged.
Example 3
- Input
- offsets = [0, 3, -5]
- Output
- [[], [0], [3], [0, 3], [-5], [0, -5], [3, -5], [0, 3, -5]]
Three trims give eight presets, each keeping the bank order of the trims it engages.
Constraints
- 1 <= offsets.length <= 10
- -10 <= offsets[i] <= 10
- All values in offsets are different
The values you return may be in any order.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def all_presets(offsets: list[int]) -> list[list[int]]:public List<List<Integer>> allPresets(int[] offsets)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 7 test cases: 7 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Subsets IIReal-world version: Distinct Shim StacksMedium
- Beautiful ArrangementReal-world version: Divisible Crate PlacementsMedium
- Partition to K Equal Sum SubsetsReal-world version: Dealing Counterweights Onto HoistsMedium
- Shopping OffersReal-world version: Cheapest Basket at the Fastener CounterMedium