188 days ago · Life · hide · Fediverse post

The challenge Find the longest substring of a string where characters appear in non-decreasing alphabetical order. If two substrings share the maximum length, return the first one. Example: the longest alphabetical substring in "asdfaaaabbbbcttavvfffffdf" is "aaaabbbbctt" (length 11). Inputs can reach 10,000 characters, so the solution must be O(n). Solution 1: index tracking (fastest, O(1) memory) Track the current run with two indices and the best run with two more — no substring allocations until the very end:

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town