Iam_Sandeep

Untitled

Jan 28th, 2026
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. class Solution:
  2.     def minWindow(self, s: str, t: str) -> str:
  3.         alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  4.         d1 = {i:0 for i in alp}
  5.         d2 = {i:0 for i in alp}
  6.         for i in t:
  7.             d1[i]+=1
  8.  
  9.         def compare():
  10.             for i in d1:
  11.                 if d1[i] == 0:
  12.                     continue
  13.                 elif  d1[i] > d2[i]:
  14.                     return False
  15.                 else:
  16.                     continue
  17.             return True
  18.  
  19.         l,r= 0,0
  20.         res,reslen = 0,float('inf')
  21.         for r in range(len(s)):
  22.             d2[s[r]]+=1
  23.             while compare():
  24.                 if (r-l+1)<reslen:
  25.                     reslen = min(reslen,r-l+1)
  26.                     res = s[l:r+1]
  27.                 d2[s[l]] -=1
  28.                 l+=1
  29.         return res if reslen!=float('inf') else ""
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment