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
For problems such as these, do not include raw_input statements or define the variable s in any way. Our automating testing will provide a value of s for you - so the code you submit in the following box should assume s is already defined. If you are confused by this instruction, please review L2 Problems 10 and 11 before you begin this problem set.

Note: This problem is fairly challenging. We encourage you to work smart. If you've spent more than a few hours on this problem, we suggest that you move on to a different part of the course. If you have time, come back to this problem after you've had a break and cleared your head.

DO IT BY YOURSELF OR YOU WILL NOT LEARN! GOOD LUCK!

def test():

index = 1
prev_index = 0
count = 0
global largest
largest = ''
test = s[prev_index]

while count < len(s):
if ord(s[index]) > ord(s[prev_index]):
test += s[index]
index += 1
prev_index += 1
elif ord(s[index]) == ord(s[prev_index]):
test += s[index]
index += 1
prev_index += 1
else:
if len(largest) < len(test):
largest = test[:]
test = s[index]
prev_index += 1
index += 1
count += 1
return largest
try:
test()
except IndexError:
pass
finally:
print largest

To solve this problem, you can use a sliding window approach. Here's a step-by-step solution in Python:

1. Initialize three variables: `longest_substring` to store the longest substring found so far, `current_substring` to store the current substring being evaluated, and `max_length` to store the length of the longest substring found.

2. Iterate through each character `c` in the given string `s`:

a. If `current_substring` is empty or `c` is greater than the last character in `current_substring`, add `c` to `current_substring`.

b. Otherwise, update `current_substring` to contain only the current character `c`.

c. If the length of `current_substring` is greater than `max_length`, update `max_length` to the length of `current_substring` and `longest_substring` to be equal to `current_substring`.

3. Print the longest substring found:

`print("Longest substring in alphabetical order is:", longest_substring)`

Here's the complete code:

```python
# assume s is already defined

longest_substring = ""
current_substring = ""
max_length = 0

for c in s:
if current_substring == "" or c >= current_substring[-1]:
current_substring += c
else:
current_substring = c

if len(current_substring) > max_length:
max_length = len(current_substring)
longest_substring = current_substring

print("Longest substring in alphabetical order is:", longest_substring)
```

This code will print the longest substring of `s` in which the letters occur in alphabetical order.

To solve this problem, we can use a sliding window approach. We iterate over the string, keeping track of the current substring in alphabetical order. If the next character is greater than or equal to the last character in the substring, we extend the substring, otherwise, we start a new substring from the current character.

Here's the step-by-step approach to solving this problem:

1. Initialize two variables, `current_substring` and `longest_substring`, to empty strings.
2. Iterate over each character, `char`, in the string, `s`.
3. Check if `char` is greater than or equal to the last character in `current_substring` by using the condition `char >= current_substring[-1]`. If it is, append `char` to `current_substring`.
4. If `char` is not greater than or equal to the last character in `current_substring`, compare the length of `current_substring` with the length of `longest_substring`. If `current_substring` is longer, update `longest_substring` with the value of `current_substring`.
5. After the loop, compare the length of `current_substring` with the length of `longest_substring` one last time to handle the case where the longest substring occurs at the end of the string.
6. Print the value of `longest_substring`.

Here's the code that solves the problem:

```python
# Assuming variable 's' is already defined

current_substring = ''
longest_substring = ''

for char in s:
if not current_substring or char >= current_substring[-1]:
current_substring += char
else:
if len(current_substring) > len(longest_substring):
longest_substring = current_substring
current_substring = char

if len(current_substring) > len(longest_substring):
longest_substring = current_substring

print("Longest substring in alphabetical order is:", longest_substring)
```

This code should output the longest substring in alphabetical order for the given string `s`.