# Permutations

Posted: 18 Nov, 2020

Difficulty: Moderate

#### A permutation is a mathematical technique that determines the number of possible arrangements in a set when the order of the arrangements matters. A string of length 'N' has 'N'! permutations.

#### Given an array of distinct integers, return all the possible permutations of the array.

##### Example:

```
'ARR[]' = [1, 2]
The size of the array is 2. So, the total number of permutations is 2! = 2. The possible permutations are [1, 2] (the array itself) and [2,1] where the position of element 1 in the original array is swapped with element 2 and vice-versa.
```

##### Note:

```
1. All the numbers in the array are unique.
2. You can return the answer in any order.
3. The original array is also a permutation of the given array.
```

##### Input format:

```
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains ‘N’ denoting the total number of elements in the array.
The second line of each test case contains ‘N’ space-separated integers denoting the elements of the array 'ARR' whose all possible permutations are to be calculated.
```

##### Output Format:

```
For each test case, return all the possible permutations of the given array of integers.
```

##### Note:

```
You don't need to print anything, it has already been taken care of. Just implement the given function.
```

##### Constraints:

```
1 <= T <= 10
1 <= N <= 7
-10 ^ 9 <= ARR[i] <= 10 ^ 9
Where ‘ARR[i]’ denotes the range of elements in the array.
Time limit: 1 sec
```

SIMILAR PROBLEMS

Best time to buy and sell stock

Posted: 2 Sep, 2022

Difficulty: Moderate

Best time to buy and sell stock II

Posted: 5 Sep, 2022

Difficulty: Moderate

Find Median from Data Stream

Posted: 9 Sep, 2022

Difficulty: Moderate

Array Rotation

Posted: 21 Oct, 2022

Difficulty: Easy

Find The Single Element

Posted: 30 Oct, 2022

Difficulty: Easy