1. Initialize an empty list called "result" to store permutations.
2. Initialize an empty list called "currentPermutation" to store the current permutation being generated.
3. Initialize a boolean array "used" of the same length as the input array "nums" to keep track of used elements.
4. Call the recursive function generatePermutations(nums, used, currentPermutation, result).
5. The generatePermutations Function:
a. If the size of "currentPermutation" is equal to the length of "nums":
i. Add a copy of "currentPermutation" to the "result" list.
ii. Return from the function.
b. Iterate through the elements of "nums":
i. If the element at index i is not used:
- Mark the element at index i as used.
- Add the element to the end of "currentPermutation".
- Recursively call generatePermutations for the remaining elements.
- Backtrack by marking the element at index i as unused and removing it from "currentPermutation".
6. Return the "result" list containing all permutations.
Click for My Solution in Github