Alphabetically Maximum Substring
Reported by candidates from Oracle's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Oracle reported this one in July 2026, and it looks easier than it is. You're asked for the lexicographically greatest substring of a string up to 200000 characters. The answer is always a suffix, so the real question is which suffix wins. The data structure the solution hinges on is just the string itself plus a pair of index pointers. No heap, no trie. If you've got an Oracle OA invite, learn the two-pointer suffix comparison and you're mostly done. StealthCoder sits there as a safety net if you blank mid-assessment.
The problem
Given a string s containing lowercase English letters, return its lexicographically greatest non-empty substring. A substring is a contiguous sequence of characters from s. String a is lexicographically greater than string b when either: At the first position where they differ, a has the greater character. b is a proper prefix of a. Function alphabeticallyMaximumSubstring(s: String) → String Examples Example 1 s = "abab" return = "bab" The substring bab begins with b, so it is greater than every substring beginning with a. It is also greater than the one-character substring b because b is its proper prefix. Example 2 s = "practice" return = "tice" The only occurrence of the greatest character t begins the substring tice, which is therefore greater than every other substring. Example 3 s = "aaaa" return = "aaaa" Every candidate contains only a. The full string is greatest because every shorter candidate is its proper prefix. Constraints 1 <= s.length <= 200000 s contains only lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: the greatest substring must run to the end of s, because extending a string always makes it larger. So you only compare suffixes. Brute force compares all of them and hits O(n^2) on input like aaaa..., which blows up at 200000. The fix is the two-pointer technique from the last-substring and minimal-rotation family. Keep a best start i, a challenger start j = i+1, and an offset k. Compare s[i+k] with s[j+k]. If equal, k++. If the challenger is bigger, set i = max(i+k+1, j) and j = i+1, reset k. If smaller, j += k+1, reset k. Stop when j+k reaches n. Return s[i:]. Common pitfall: forgetting to skip ahead by k, which quietly turns it back into quadratic time. If your mind goes blank during the live Oracle OA, StealthCoder can supply this loop as a hedge.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Alphabetically Maximum Substring cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as last substring in lexicographical order. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Oracle's OA.
Oracle reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Alphabetically Maximum Substring FAQ
What's the trick to Alphabetically Maximum Substring?+
The answer is always a suffix, since any substring can be extended to be larger. That cuts the problem to finding the greatest suffix. Then use two pointers with an offset to compare candidates in linear time instead of comparing every pair.
How hard is this really?+
The idea is short, but the O(n) pointer logic is easy to get wrong. Most people can write the brute force in two minutes. The hard part is the skip rule that keeps it linear on inputs with long repeated runs.
Will brute force pass with n up to 200000?+
Probably not. Comparing all suffixes is O(n^2) in the worst case, and a string like all a's forces long comparisons every time. With 200000 characters you need the linear two-pointer approach or a suffix array.
What edge cases should I test?+
Test a string of all the same letter, like aaaa, which should return the whole string. Test a single character. Test a case where the max letter appears once, like practice. Test repeating patterns such as abab, where ties need the offset logic.
How do I prep for this in 48 hours?+
Write the two-pointer greatest-suffix loop from memory three times. Trace it by hand on abab and aaaa. Then do the same for the related last-substring problem. Focus on why the pointer jumps are safe, not on memorizing code.