Skip to content

Instantly share code, notes, and snippets.

@neanias
Last active February 1, 2018 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neanias/cbb0d5a16081f5f7e0a58aef72ed7ad0 to your computer and use it in GitHub Desktop.
Save neanias/cbb0d5a16081f5f7e0a58aef72ed7ad0 to your computer and use it in GitHub Desktop.
MIT Problem
string = "abcadefzab"
longest_string = ''
current_string = ''
last_char = ''
for char in string:
if char >= last_char:
current_string += char
elif last_char > char:
if len(current_string) > len(longest_string):
longest_string = current_string
current_string = char
last_char = char
if len(current_string) > len(longest_string):
longest_string = current_string
print(longest_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment