All problems
0090MediumArrayBacktrackingBit Manipulation

Every Gain Preset

Tracked in this browser only
Write code

Trains the technique from

LeetCode 78Subsets

This 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 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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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