Skip to content

Instantly share code, notes, and snippets.

@devils-ey3
Last active September 21, 2016 10:43
Show Gist options
  • Save devils-ey3/ea16140ca48635fb346fe276bae2b40d to your computer and use it in GitHub Desktop.
Save devils-ey3/ea16140ca48635fb346fe276bae2b40d to your computer and use it in GitHub Desktop.
Write a program that prints the longest substring which the letters occur in alphabetical order.
si = ['azcbobobegghakl', 'abcdefghijklmnopqrstuvwxyz', 'nqlkcvjkwytg', 'bovgfeiromsncq']
for s in si:
max_subStr = ''
for i in range(len(s)):
sub_string = s[i]
char_count = 0
while i + 1 < len(s) and s[i]<=s[i+1]:
char_count+=1
i+=1
sub_string+=s[i]
if len(sub_string)> len(max_subStr):
max_subStr = sub_string
print(max_subStr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment