The python program is supposed to find the longest consecutive sub-string in alphabetical order in a given string.

Note that the order determination is case insensitive, i.e. the string "Ab" is considered to be in alphabetical order. You can assume that the input will not have string where the number of possible consecutive sub-strings in alphabetical order is 0. i.e. the input will not have a string like "zxec".

For example:

Sample Input 1: Hello
Sample Output 1: ello

Longest substring in alphabetical order python

prevChar = ""
curr_longest = ""
longest = ""

for char in string:
    if (prevChar.lower()<=char.lower()):
        curr_longest += char
        if len(curr_longest) > len(longest):
            longest= curr_longest
        curr_longest = char
    prevChar = char
print( longest )