I have wriiten a solution for the same problem but when input is string

programming
Tags: #<Tag:0x00007f242644b3c0>

#1

#Time complexity : O(n!)
#Space Complexity : O(N)
def permuations(string, rem_string,result):
if len(rem_string)==0:
result.append(string)
else:
for i in range(len(rem_string)):
string=string+rem_string[i]
rem_string=rem_string[:i]+rem_string[i+1:]
permuations(string,rem_string,result)

string=input()
result=[]
permuations("",string,result)
print(“Total number of permuations:”+str(output))
print(“Permutations:\n”)
print(result)

This above code gives error, and can someone explain me why? Since string is immutable and will be passed by value , it works fine if i create a new variable and pass in the recursive call?
Can anyone tell me what is the bug here?