All problems
0081MediumArrayBacktracking

Calibration Run Orders

Tracked in this browser only
Write code

Trains the technique from

LeetCode 46Permutations

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 calibration bench applies a set of signed offsets, given as offsets, to an instrument. Each offset is applied exactly once per run, and the instrument drifts differently depending on which offset comes first, so the lab wants to inspect every run order before choosing one.

Return every arrangement of offsets that uses each offset exactly once, so n offsets yield n! arrangements. Each arrangement lists the offsets in the sequence they would be applied. The arrangements themselves may be handed back in whatever sequence you like.

The offsets are pairwise distinct, so no two arrangements are identical.

Examples

Example 1

Input
offsets = [-10, 0, 10]
Output
[[-10, 0, 10], [-10, 10, 0], [0, -10, 10], [0, 10, -10], [10, -10, 0], [10, 0, -10]]

Three offsets admit six run orders, one for each choice of which offset is applied first paired with each ordering of the remaining two.

Example 2

Input
offsets = [1, 2]
Output
[[1, 2], [2, 1]]

With two offsets the bench can only apply them in one order or the other.

Example 3

Input
offsets = [5]
Output
[[5]]

A single offset leaves nothing to reorder, so exactly one run order exists.

Constraints

  • 1 <= offsets.length <= 6
  • -10 <= offsets[i] <= 10
  • All of the offsets are distinct

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 run_orders(offsets: list[int]) -> list[list[int]]:
Java
public List<List<Integer>> runOrders(int[] offsets)
September 7
Apply