Algorithms Playbook
← All problems
MediumPermutations →Similar to: Permutations

Every seating order

Problem

Given an array of distinct integers, return all possible orderings of its elements, in any order.

Examples

Input: [1, 2, 3]

Output: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]

Input: [1]

Output: [1]

Hints

    Try it first. Every hint reveals a bit more.

    Solution