Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
akashsonowal authored Nov 16, 2023
1 parent 7973133 commit 8462c33
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions interview_prep/coding/permutation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def permute(nums):
res = []
n = len(nums)
if n <= 1:
return [nums]
else:
for i in range(len(nums)):
for combo in permute(nums[:i] + nums[i+1:]):
res.append([nums[i]] + combo)
return res

if __name__ == "__main__":
assert permute([2, 3, 4]) == [[2, 3, 4], [2, 4, 3], [3, 2, 4], [3, 4, 2], [4, 2, 3], [4, 3, 2]]

0 comments on commit 8462c33

Please sign in to comment.