The challenge Find the longest substring of a string where characters are in non-decreasing alphabetical order. If multiple substrings share the maximum length, return the first one. Example: the longest alphabetical substring in "asdfaaaabbbbcttavvfffffdf" is "aaaabbbbctt" (length 11). Inputs can be up to 10,000 characters, so the solution must be O(n). Solution 1: index tracking (fastest, O(1) memory) Track the start of the current run and the best run seen so far — only indices, no substrings:
No comments yet. Log in to reply on the Fediverse. Comments will appear here.