fork download
  1. from collections import defaultdict
  2.  
  3. def solve(lst):
  4. found, total = 0, len(set(lst))
  5. hist = defaultdict(int)
  6. l = 0
  7. ans = len(lst)
  8. for r in xrange(len(lst)):
  9. occ = hist[lst[r]] = hist[lst[r]] + 1
  10. if occ == 1:
  11. found += 1
  12. while l <= r and found == total:
  13. ans = min(ans, r - l + 1)
  14. occ = hist[lst[l]] = hist[lst[l]] - 1
  15. if not occ:
  16. found -= 1
  17. l += 1
  18. return ans
Success #stdin #stdout 0.01s 9072KB
stdin
Standard input is empty
stdout
Standard output is empty