Assume s
is a string of lower case characters.
Write a program that prints the longest substring of s
in which the letters occur in alphabetical order. For example, if s = 'azcbobobegghakl'
, then your program should print
Longest substring in alphabetical order is: beggh
In the case of ties, print the first substring. For example, if s = 'abcbcd'
, then your program should print
Longest substring in alphabetical order is: abc# Paste your code into this box
a=0
arr = [i for i in range(len(s))]
while a <= (len(s)-1):
b=s[a]
if a<(len(s)-1):
while s[a] <= s[a+1]:
b=b+s[a+1]
arr[a]=b
a=a+1
if a==(len(s)-1):
break
b=''
arr[a]=b
a=a+1
sorted(arr)
t=sorted(arr,key=len,reverse=True)[0]
if t=='':
print('Longest substring in alphabetical order is:'+ s[0])
else:
print ('Longest substring in alphabetical order is:'+ sorted(arr,key=len,reverse=True)[0])