Permutations
Real-world version: Calibration Run OrdersThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def run_orders(offsets: list[int]) -> list[list[int]]:public List<List<Integer>> runOrders(int[] offsets)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 6 test cases: 6 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