Permutations

Given a collection of numbers, return all possible permutations.

Example:

[1,2,3] will have the following permutations:

[1,2,3]
[1,3,2]
[2,1,3] 
[2,3,1] 
[3,1,2] 
[3,2,1]

NOTE

  • No two entries in the permutation sequence should be the same.
  • For the purpose of this problem, assume that all the numbers in the collection are unique.

Warning : DO NOT USE LIBRARY FUNCTION FOR GENERATING PERMUTATIONS.
Example : next_permutations in C++ / itertools.permutations in python.
If you do, we will disqualify your submission retroactively and give you penalty points.

Interview Code Editor
Hints
  • Solution Approach
  • Complete Solution
4960 successful submissions.
Asked In:
  • Microsoft
  • Adobe
  • Google
Click here to jump start your coding interview preparation