Most optimized way to write a recursive function which returns a new string in which all duplicate consecutive characters are separated by a ‘*’. E.g. for “hello” return “hel*lo”

def dup(str, n, newstr="", index=0, p=0):
if index == n-1:
newstr = newstr + str[p:n]
print(newstr)
return
if str[index] == str[index+1]:
newstr = newstr + str[p:index+1] + “*” + str[index+1]
p = index+2
dup(str, n, newstr, index+1, p)
dup(“hello”, 5)