From Bulky Mosquito, 1 Week ago, written in Text.
Embed
  1. def longestSubstring(s, m):
  2.     d = {}
  3.     i = r = 0
  4.     l = -1
  5.     for c in s:
  6.         d[c] = i
  7.         if len(d) > m:
  8.             l = d.pop(min(d,key=d.get))
  9.         r = max(i - l, r)
  10.         i += 1
  11.     return r/m and r
  12.