Problem in Recursion

Question Link → Loading...

I am trying to write a recursive function to solve it but the set is not getting clear.

My code:

class Solution(object):
    def hasAllCodes(self, s, k,x=set(),i=0):
        if(i==len(s)-k+1):
            y = len(x)
            x = set()
            i = 0
            return True if(y==(2**k)) else False
        else:
            x.add(s[i:i+k])
            return self.hasAllCodes(s,k,x,i+1)

Please let me know how to solve it using recursion.

Check the following recursive solution.

Accepted