fork download
  1. from collections import OrderedDict
  2.  
  3. def get_longest_unique_substring(s):
  4. window = OrderedDict()
  5. longest_end = longest_size = 0
  6. for index, char in enumerate(s):
  7. while char in window:
  8. window.popitem(last=False)
  9. window[char] = True
  10. if (size := len(window)) > longest_size:
  11. longest_end = index + 1
  12. longest_size = size
  13. return s[longest_end - longest_size: longest_end]
  14.  
  15. print(get_longest_unique_substring('aabcdefdabcdefghijbad'))
Success #stdin #stdout 0.03s 9824KB
stdin
Standard input is empty
stdout
abcdefghij