Last active
September 21, 2016 10:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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