I am trying to recursively obtain all subsequences for an input string. While I am getting the said subsequences, another element keeps getting added as well. I cannot figure out what is producing this element.
**CODE: **
class Solution:
def subs(self,word,index,cs,arr=[]):
if(len(word)==index):
return cs
else:
l=word[index]
arr.append(self.subs(word,index+1,cs,arr))
arr.append(self.subs(word,index+1,cs+l,arr))
return arr
def numMatchingSubseq(self, s: str):
x=self.subs(s,0,'')
print(x)
x=Solution()
x.numMatchingSubseq('ab')
MY OUTPUT:
['', 'b', [...], 'a', 'ab', [...]]
EXPECTED OUTPUT:
['', 'b', 'a', 'ab']