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:
No comments yet. Log in to reply on the Fediverse. Comments will appear here.