def func(i,uniqueSubString): nonlocal ans,n if(i==n): ans=max(ans,len(uniqueSubString)) if(len(uniqueSubString)==ans): print(ans,uniqueSubString) return for ind in range(i+1,n+1): if(s[i:ind] not in uniqueSubString): uniqueSubString.add(s[i:ind]) func(ind,uniqueSubString) uniqueSubString.remove(s[i:ind])
func(0,set()) return ans # s="wwwzfvedwfvhsww" # w ww z f v e d wf vh sww # #ANS=10 #www z f v e d w fv h s ww #ANS=11 # s[i]==s[i:i+1]
# Day-21
class Solution:
def maxUniqueSplit(self, s: str) -> int:
n=len(s)
#uniqueSubString=set()
ans=0
def func(i,uniqueSubString):
nonlocal ans,n
if(i==n):
ans=max(ans,len(uniqueSubString))
if(len(uniqueSubString)==ans):
print(ans,uniqueSubString)
return
for ind in range(i+1,n+1):
if(s[i:ind] not in uniqueSubString):
uniqueSubString.add(s[i:ind])
func(ind,uniqueSubString)
uniqueSubString.remove(s[i:ind])
func(0,set())
return ans
# s="wwwzfvedwfvhsww"
# w ww z f v e d wf vh sww
# #ANS=10
#www z f v e d w fv h s ww
#ANS=11
# s[i]==s[i:i+1]