Skip to content

Instantly share code, notes, and snippets.

@alaisgomes
Created July 14, 2019 12:03
Show Gist options
  • Save alaisgomes/598ca5612df3d37ebbb372582b7d0561 to your computer and use it in GitHub Desktop.
Save alaisgomes/598ca5612df3d37ebbb372582b7d0561 to your computer and use it in GitHub Desktop.
Find largest substring without repeating characters
def find_substring(string):
""" Function that returns the longest
substring without repetition
"""
max_length = 0
init_sub = -1
letters_dict = {}
for idx, letter in enumerate(string):
if letter in letters_dict:
init_sub = max(init_sub, letters_dict[letter])
max_length = max(max_length, idx - init_sub)
letters_dict[letter] = idx
return max_length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment