Show problems as
Classic problem #78MediumArrayBacktrackingBit Manipulation

Subsets

Real-world version: Every Gain Preset
Tracked in this browser only
Read Subsets on LeetCode(opens in a new tab)

The 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.

Python
def all_presets(offsets: list[int]) -> list[list[int]]:
Java
public List<List<Integer>> allPresets(int[] offsets)