Skip to content

Instantly share code, notes, and snippets.

@pyrofolium
Created January 28, 2016 21:12
Show Gist options
  • Save pyrofolium/b43b659b4c46ff5fc61e to your computer and use it in GitHub Desktop.
Save pyrofolium/b43b659b4c46ff5fc61e to your computer and use it in GitHub Desktop.
def longest_non_repeating_string(input_str):
repeated_chars = {}
longest_string = ""
current_string = ""
for char in input_str:
if char in repeated_chars:
current_string = ""
repeated_chars = {}
current_string += char
repeated_chars[char] = True
if len(current_string) > len(longest_string):
longest_string = current_string
return longest_string
print longest_non_repeating_string("broadband")
print longest_non_repeating_string("hello abcdefhijkl")
print longest_non_repeating_string("madam am i")
print longest_non_repeating_string("hello worldfair")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment