My code takes in a string and returns a list of strings that are permutations of the input string. (No repeats)
def perm(slist, c):
rTup = []
for s in slist: #O(n!)
for i in range(len(s) + 1): #O(n)
rstr = s[:i] + c + s[i:] #O(n)
rTup.append(rstr)
return rTup
def permWrap(s): #wrapper
slist = [s]
rlist = [""]
for i in reversed(range(-1,len(s)-1)): #O(n)
rlist = perm(rlist , s[i+1])
return list(set(rlist)) #O(n!)
permWrap("abbc")
I put little comments for what I believe the time complexity is at each step. However, I could be wrong.
I am thinking that the time complexity is O(n! * n^3). Is that correct?
In addition, how would you make this function more efficient?