Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
- For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
- '''
- class Solution:
- def findSubString(self, s):
- tar=set(s)
- d={}
- have,need=0,len(tar)
- t={}
- l=0
- ans=float('inf')
- for r in range(len(s)):
- c=s[r]
- d[c]=d.get(c,0)+1
- if c in d and d[c]==1:
- have+=1
- while have==need:
- ans=min(ans,r-l+1)
- d[s[l]]-=1
- if d[s[l]]==0 and s[l] in tar:
- have-=1
- l=l+1
- return ans
Add Comment
Please, Sign In to add comment