comefrom: <garvit244>340_1.py
code: def lengthOfLongestSubstringKDistinct( S, K):
      charMapping, start = {}, 0
      result = 0
      for end, s in enumerate(S):
          if s in charMapping:
              charMapping[s] += 1
          else:
              charMapping[s] = 1
      
          if len(charMapping) <= K:
              result = max(result, end-start+1)
          else:
              while len(charMapping) > K :
                  character = S[start]
                  freq = charMapping[character]
                  if freq == 1:
                      del charMapping[character]
                  else:
                      charMapping[character] -= 1
                  start += 1
      return result
masked: def sample_funcname ( var_0 , var_1 ) :
      var_2 , var_4 = { } , 0
      var_5 = 0
      for var_7 , var_8 in enumerate ( var_0 ) :
          if var_8 in var_2 :
              var_2 [ var_8 ] += 1
          else :
              var_2 [ var_8 ] = 1
          if len ( var_2 ) <= var_1 :
              var_5 = max ( var_5 , var_7 - var_4 + 1 )
          else :
              while len ( var_2 ) > var_1 :
                  var_12 = var_0 [ var_4 ]
                  var_13 = var_2 [ var_12 ]
                  if var_13 == 1 :
                      del var_2 [ var_12 ]
                  else :
                      var_2 [ var_12 ] -= 1
                  var_4 += 1
      return var_5
  